mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
5f700615b9
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
25 lines
893 B
TypeScript
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)
|
|
}
|
|
}
|