Files
TREK/client/src/mobile/screens/trip/sheets/uploadBookingFiles.ts
T
Maurice 5f700615b9 fix(mobile): files attached while editing a booking are uploaded on save
The phone booking and transport sheets collect picked files and upload them
after the save, but only when the record was new. Editing an existing booking
showed the picked files in the sheet, then dropped them on Update without a
word. The upload now runs after every save that comes back with a record,
through one helper both sheets share. A save that fails uploads nothing.

Closes #2534
2026-09-29 21:16:26 +02:00

25 lines
893 B
TypeScript

import type { TripPlanner } from '../MTripShell'
/**
* Uploads the files picked in a booking or transport sheet against the saved
* record. Runs after both a create and an edit: the sheet only holds files the
* user just picked, so nothing is uploaded twice, and skipping the edit dropped
* them without a word (#2534). A save that did not come back with a record
* uploads nothing.
*/
export async function uploadBookingFiles(
planner: Pick<TripPlanner, 'tripId' | 'tripActions' | 'canUploadFiles'>,
savedId: number | undefined,
files: File[],
description: string,
): Promise<void> {
if (!savedId || !planner.canUploadFiles) return
for (const file of files) {
const fd = new FormData()
fd.append('file', file)
fd.append('reservation_id', String(savedId))
fd.append('description', description)
await planner.tripActions.addFile(planner.tripId, fd)
}
}