fix(bookings): keep the editor open until a booking's files are uploaded

Saving a booking or a transport closed the editor and reported success
before the travellers and picked files were written. A failed upload left
a booking without some of its PDFs, no list to retry from, and a create
form that would add a duplicate when saved again. On desktop a file picked
on an existing booking went up at once and vanished when that failed.

The planner's save now takes the editor's follow-up as a step it waits
for: it stores the booking, runs the traveller write and the uploads, and
only then says so and closes. Each file that lands leaves the list, so a
failure leaves exactly the files still to send, and the editor keeps the
stored booking so the retry updates it instead of creating another one,
without a second linked cost or stay. All four editors (desktop booking
and transport dialogs, both phone sheets) share this through
useBookingFollowUp, an import review only moves on once an item's files
are up, and desktop files picked on a saved booking wait for Update like
on the phone.

Closes #2883
This commit is contained in:
Maurice
2026-10-29 14:20:57 +01:00
parent 7d669cb5c3
commit b06e3e6266
47 changed files with 642 additions and 341 deletions
@@ -1,4 +1,4 @@
// FE-PLANNER-BOOKINGFORM-001 to -010: the travellers, picked files, attached files
// FE-PLANNER-BOOKINGFORM-001 to -012: the travellers, picked files, attached files
// and expense requests of the transport and booking forms, desktop and phone alike.
import { typeToCostCategory } from '@trek/shared';
import { describe, expect, it, vi } from 'vitest';
@@ -11,6 +11,7 @@ import {
expenseRequestAfterSave,
filesNeedConnection,
pendingImportExpense,
retriedSave,
toggledTraveler,
travelerIdsOf,
travelersChanged,
@@ -62,6 +63,40 @@ describe('bookingFormModel', () => {
expect(upload).not.toHaveBeenCalled();
});
it('FE-PLANNER-BOOKINGFORM-011: each landed file is reported, and the first failure stops the rest (#2883)', async () => {
const files = [new File(['a'], 'a.pdf'), new File(['b'], 'fail.pdf'), new File(['c'], 'c.pdf')];
const upload = vi.fn(async (fd: FormData) => {
if ((fd.get('file') as File).name === 'fail.pdf') throw new Error('413');
});
const onUploaded = vi.fn();
await expect(uploadBookingFiles(upload, 42, files, 'Hotel stay', onUploaded)).rejects.toThrow('413');
expect(onUploaded.mock.calls).toEqual([[files[0]]]);
expect(upload).toHaveBeenCalledTimes(2);
});
it('FE-PLANNER-BOOKINGFORM-012: a retried save creates no second cost and keeps the stay it already made', () => {
const stored = buildReservation({ id: 6, accommodation_id: 31 } as Partial<Reservation>);
expect(
retriedSave(
{ title: 'Ryokan', type: 'hotel', accommodation_id: null, create_budget_entry: { total_price: 90 } },
stored
)
).toEqual({
title: 'Ryokan',
type: 'hotel',
accommodation_id: 31,
});
expect(retriedSave({ title: 'Ryokan', type: 'hotel', accommodation_id: 12 }, stored)).toEqual({
title: 'Ryokan',
type: 'hotel',
accommodation_id: 12,
});
expect(retriedSave({ title: 'ICE', type: 'train', create_budget_entry: true }, stored)).toEqual({
title: 'ICE',
type: 'train',
});
});
it('FE-PLANNER-BOOKINGFORM-008: without an upload handler the picked files are skipped and the save is not rejected', async () => {
await expect(uploadBookingFiles(undefined, 42, [new File(['a'], 'a.pdf')], 'Hotel stay')).resolves.toBeUndefined();
});