mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
Editing a booking on the phone erased the stop it was linked to. The sheet seeded its assignment from the create-for-a-stop flag, which is null on an edit, and saved that straight back over a link the user had made on the desktop; the server writes the field whenever the key is present. It now seeds from the booking being edited, and the picker the desktop dialog has always had sits in the sheet too, so a stop can be seen, changed and cleared from a phone. The option list moved to its own module rather than being copied. Two more of the same shape, found on the way. The endpoint set was sent as an empty list on every save, and the server swaps the whole set when that key is present, so editing a transit booking dropped its stations; neither form edits endpoints, so an edit no longer sends the key at all. And the sheet's Files block listed only what was picked in this session, so a file uploaded from the desktop was invisible on the phone. It lists what is attached now, resolved the way the desktop resolves it. A place also shows the files of the bookings that sit on it, on the phone and on the desktop: a confirmation lives on the booking, and the place card was the one screen that could not reach it.
This commit is contained in:
@@ -19,6 +19,7 @@ import { resolveTrackColor, inheritedTrackColor } from '../../../../components/M
|
||||
import { avatarSrc } from '../../../../utils/avatarSrc'
|
||||
import { safeHttpUrl } from '../../../../utils/safeUrl'
|
||||
import { openFile } from '../../../../utils/fileDownload'
|
||||
import { filesForPlace } from '../../../../utils/placeFiles'
|
||||
import { getNavigationTargets, openNavigationTarget } from '../../../../components/Planner/placeNavigation'
|
||||
import { NavigationMenu } from '../../../../components/shared/NavigationMenu'
|
||||
import { getAssignmentReservations } from '../../../../utils/dayMerge'
|
||||
@@ -151,8 +152,12 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
setParticipantPickerOpen(false)
|
||||
}
|
||||
|
||||
const placeFiles = (planner.files || []).filter(f =>
|
||||
!f.deleted_at && (String(f.place_id) === String(place?.id) || (f.linked_place_ids || []).includes(place?.id ?? -1)),
|
||||
// Its own files plus the ones on the bookings that hang on it (#2217).
|
||||
const placeFiles = filesForPlace(
|
||||
planner.files,
|
||||
place?.id,
|
||||
planner.reservations,
|
||||
assignmentInDay ? [assignmentInDay.id] : [],
|
||||
)
|
||||
|
||||
const handleImagePick = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Check, FileText, Hotel, Link2, ParkingSquare, Plus, Ticket, Users, Utensils } from 'lucide-react'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Check, ExternalLink, FileText, Hotel, Link2, ParkingSquare, Plus, Ticket, Users, Utensils } from 'lucide-react'
|
||||
import MSheet from '../../../components/MSheet'
|
||||
import { useAddonStore } from '../../../../store/addonStore'
|
||||
import { useTranslation } from '../../../../i18n'
|
||||
@@ -11,6 +11,8 @@ import CustomTimePicker from '../../../../components/shared/CustomTimePicker'
|
||||
import { CustomDatePicker } from '../../../../components/shared/CustomDateTimePicker'
|
||||
import { Eyebrow, FIELD_AREA_CLS, FIELD_CLS, FormSheetFooter, FormSheetHeader } from './PlSheetChrome'
|
||||
import PlFileAttach from './PlFileAttach'
|
||||
import { buildAssignmentOptions } from '../../../../components/Planner/assignmentOptions'
|
||||
import { openFile } from '../../../../utils/fileDownload'
|
||||
import GuestBadge from '../../../../components/shared/GuestBadge'
|
||||
import { SPLIT_COLORS } from '../../../../components/Budget/BudgetPanel.constants'
|
||||
import { useTripStore } from '../../../../store/tripStore'
|
||||
@@ -57,6 +59,7 @@ export default function MReservationSheet({ planner, onOpenExpense }: MReservati
|
||||
showReservationModal, setShowReservationModal,
|
||||
editingReservation, setEditingReservation, reservationPrefill,
|
||||
bookingForAssignmentId, setBookingForAssignmentId,
|
||||
assignments, files,
|
||||
importReviewActive, advanceImportReview,
|
||||
handleSaveReservation, canUploadFiles, tripActions,
|
||||
} = planner
|
||||
@@ -67,6 +70,11 @@ export default function MReservationSheet({ planner, onOpenExpense }: MReservati
|
||||
|
||||
const [form, setForm] = useState(EMPTY)
|
||||
const [pendingFiles, setPendingFiles] = useState<File[]>([])
|
||||
const assignmentOptions = useMemo(
|
||||
() => buildAssignmentOptions(days, assignments, t, locale),
|
||||
[days, assignments, t, locale],
|
||||
)
|
||||
|
||||
// Travelers assigned to this booking (#1517) — seeded from the editing
|
||||
// reservation on open, persisted separately after the save resolves.
|
||||
const [travelerIds, setTravelerIds] = useState<Set<number>>(new Set())
|
||||
@@ -77,10 +85,15 @@ export default function MReservationSheet({ planner, onOpenExpense }: MReservati
|
||||
const [snap, setSnap] = useState<{ res: typeof editingReservation; assignmentId: number | null }>(
|
||||
{ res: null, assignmentId: null },
|
||||
)
|
||||
// The stop this booking hangs on. Seeded from the booking being edited, not
|
||||
// only from the create-for-a-stop flag, because saving used to write the flag
|
||||
// straight back and an edit therefore erased the link (#2216).
|
||||
const [assignmentId, setAssignmentId] = useState<number | ''>('')
|
||||
|
||||
useEffect(() => {
|
||||
if (!showReservationModal) return
|
||||
setSnap({ res: editingReservation, assignmentId: bookingForAssignmentId ?? null })
|
||||
setAssignmentId(bookingForAssignmentId ?? editingReservation?.assignment_id ?? '')
|
||||
expenseIntentRef.current = false
|
||||
setPendingFiles([])
|
||||
setTravelerIds(new Set((editingReservation?.travelers || []).map(tv => tv.user_id)))
|
||||
@@ -147,6 +160,16 @@ export default function MReservationSheet({ planner, onOpenExpense }: MReservati
|
||||
}, [showReservationModal])
|
||||
|
||||
const res = snap.res
|
||||
// Files already on this booking. The sheet used to list only the ones picked
|
||||
// in this session, so an upload from the desktop was invisible here (#2217).
|
||||
const attachedFiles = res?.id
|
||||
? (files || []).filter(f =>
|
||||
!f.deleted_at && (
|
||||
String(f.reservation_id) === String(res.id) ||
|
||||
(f.linked_reservation_ids || []).includes(res.id)
|
||||
),
|
||||
)
|
||||
: []
|
||||
const isHotel = form.type === 'hotel'
|
||||
const set = (field: keyof typeof EMPTY, value: string | number) => setForm(prev => ({ ...prev, [field]: value }))
|
||||
|
||||
@@ -233,11 +256,15 @@ export default function MReservationSheet({ planner, onOpenExpense }: MReservati
|
||||
location: isHotel ? form.hotel_address : form.location,
|
||||
confirmation_number: form.confirmation_number,
|
||||
notes: form.notes, url: form.url,
|
||||
assignment_id: (isHotel && !form.accommodation_id) ? null : (snap.assignmentId || null),
|
||||
assignment_id: (isHotel && !form.accommodation_id) ? null : (assignmentId || null),
|
||||
accommodation_id: isHotel ? (form.accommodation_id || null) : null,
|
||||
place_id: isHotel ? null : (form.place_id || null),
|
||||
metadata: Object.keys(metadata).length > 0 ? metadata : null,
|
||||
endpoints: [], needs_review: false,
|
||||
// Omitted on an edit for the same reason as the desktop dialog: the
|
||||
// server swaps the whole endpoint set when the key is present, and this
|
||||
// sheet never edits endpoints (#2216).
|
||||
...(snap.res?.id ? {} : { endpoints: [] }),
|
||||
needs_review: false,
|
||||
}
|
||||
if (isHotel && (form.hotel_start_day || form.hotel_end_day)) {
|
||||
saveData.create_accommodation = {
|
||||
@@ -556,7 +583,46 @@ export default function MReservationSheet({ planner, onOpenExpense }: MReservati
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* LINK TO A STOP IN THE PLAN (#2216) */}
|
||||
{!isHotel && assignmentOptions.length > 0 && (
|
||||
<>
|
||||
<Eyebrow className="mb-[6px] mt-3 uppercase">{t('reservations.linkAssignment')}</Eyebrow>
|
||||
<CustomSelect
|
||||
value={assignmentId}
|
||||
onChange={value => {
|
||||
setAssignmentId(value === '' ? '' : Number(value))
|
||||
const opt = assignmentOptions.find(o => o.value === value)
|
||||
// Same courtesy as the desktop dialog: an undated booking takes
|
||||
// the day of the stop it was just linked to.
|
||||
if (opt?.dayDate) setForm(prev => (prev.reservation_time ? prev : { ...prev, reservation_time: opt.dayDate! }))
|
||||
}}
|
||||
placeholder={t('reservations.pickAssignment')}
|
||||
options={[{ value: '', label: t('reservations.noAssignment') }, ...assignmentOptions]}
|
||||
searchable
|
||||
size="sm"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* FILES */}
|
||||
{attachedFiles.length > 0 && (
|
||||
<>
|
||||
<Eyebrow className="mb-[6px] mt-3 uppercase">{t('files.title')}</Eyebrow>
|
||||
<div className="flex flex-col gap-1">
|
||||
{attachedFiles.map(f => (
|
||||
<button
|
||||
key={f.id}
|
||||
type="button"
|
||||
onClick={() => openFile(f.url, f.original_name)}
|
||||
className="flex w-full items-center gap-2 rounded-[10px] bg-[color:var(--m-ic)] px-[10px] py-[7px] text-left"
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate text-[0.75rem] font-medium">{f.original_name}</span>
|
||||
<ExternalLink size={11} strokeWidth={2} className="flex-none text-m-faint" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{canUploadFiles && (
|
||||
<PlFileAttach
|
||||
planner={planner}
|
||||
|
||||
Reference in New Issue
Block a user