mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
fix(mail-ingest): set an inbox entry aside once its booking is saved through Fill in yourself
The entry stayed pending after the prefilled booking was saved, kept its Add action and counted in the badge, so it could be added a second time.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-TP-BOOKING-001 to FE-TP-BOOKING-016
|
||||
// FE-TP-BOOKING-001 to FE-TP-BOOKING-017
|
||||
//
|
||||
// Booking writes and the review before an import is saved, driven straight through
|
||||
// useBookingEdits. Every write goes to a recorded stand-in for the store's actions and
|
||||
@@ -355,6 +355,27 @@ describe('useBookingEdits', () => {
|
||||
await waitFor(() => expect(fixed.setTripAccommodations).toHaveBeenLastCalledWith([]))
|
||||
})
|
||||
|
||||
it('FE-TP-BOOKING-017: a review started with a saved hook hears of the saved booking once, a skipped one never', async () => {
|
||||
const { result } = renderEdits()
|
||||
const onSaved = vi.fn()
|
||||
act(() => { result.current.startImportReview(items(hotelItem), [], 'bookings', onSaved) })
|
||||
await act(async () => { await result.current.handleSaveReservation({ title: 'Ryokan', type: 'hotel' } as never) })
|
||||
expect(onSaved).toHaveBeenCalledTimes(1)
|
||||
await act(async () => { await result.current.handleSaveReservation({ title: 'Ryokan', type: 'hotel' } as never) })
|
||||
expect(onSaved).toHaveBeenCalledTimes(1)
|
||||
|
||||
const onTransport = vi.fn()
|
||||
act(() => { result.current.startImportReview(items(flightItem), [], 'transports', onTransport) })
|
||||
await act(async () => { await result.current.handleSaveTransport({ title: 'NRT to CDG', type: 'flight' }) })
|
||||
expect(onTransport).toHaveBeenCalledTimes(1)
|
||||
|
||||
const onSkipped = vi.fn()
|
||||
act(() => { result.current.startImportReview(items(hotelItem), [], 'bookings', onSkipped) })
|
||||
act(() => { result.current.advanceImportReview() })
|
||||
await act(async () => { await result.current.handleSaveReservation({ title: 'Other', type: 'hotel' } as never) })
|
||||
expect(onSkipped).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FE-TP-BOOKING-012: the bridge hands this trip\'s finished import to the review, from memory or from IndexedDB', async () => {
|
||||
const file = new File(['x'], 'mail.pdf')
|
||||
useBackgroundTasksStore.setState({
|
||||
|
||||
@@ -57,6 +57,14 @@ export function useBookingEdits(options: BookingEditsOptions) {
|
||||
// by the global widget, so by then the state has remounted back to its default.
|
||||
// The value comes off the persisted job (#2076).
|
||||
const importKindRef = useRef<'transports' | 'bookings'>('bookings')
|
||||
// Told when a booking of this review is saved, for the mail inbox entry it came from.
|
||||
const importSavedRef = useRef<(() => void) | null>(null)
|
||||
|
||||
const importSaved = () => {
|
||||
const saved = importSavedRef.current
|
||||
importSavedRef.current = null
|
||||
saved?.()
|
||||
}
|
||||
|
||||
// A save is done once the editor's own part (travellers, files) is done too:
|
||||
// only then does it say so and close. Until then the editor stays open, so a
|
||||
@@ -109,6 +117,7 @@ export function useBookingEdits(options: BookingEditsOptions) {
|
||||
accommodationRepo.list(tripId).then(d => setTripAccommodations(d.accommodations || [])).catch(() => {})
|
||||
}
|
||||
await afterSave?.(r)
|
||||
if (!editingReservation) importSaved()
|
||||
toast.success(t(editingReservation ? 'trip.toast.reservationUpdated' : 'trip.toast.reservationAdded'))
|
||||
setShowReservationModal(false)
|
||||
if (editingReservation) setEditingReservation(null)
|
||||
@@ -132,6 +141,7 @@ export function useBookingEdits(options: BookingEditsOptions) {
|
||||
if (data.create_budget_entry) await tripActions.loadBudgetItems?.(tripId)
|
||||
}
|
||||
await afterSave?.(r)
|
||||
if (!editingTransport) importSaved()
|
||||
toast.success(t(editingTransport ? 'trip.toast.reservationUpdated' : 'trip.toast.reservationAdded'))
|
||||
setShowTransportModal(false)
|
||||
setEditingTransport(null)
|
||||
@@ -224,10 +234,12 @@ export function useBookingEdits(options: BookingEditsOptions) {
|
||||
items: BookingImportPreviewItem[],
|
||||
sourceFiles: File[] = [],
|
||||
kind: 'transports' | 'bookings' = 'bookings',
|
||||
onSaved: (() => void) | null = null,
|
||||
) => {
|
||||
if (!items.length) return
|
||||
importSourceFilesRef.current = sourceFiles
|
||||
importKindRef.current = kind
|
||||
importSavedRef.current = onSaved
|
||||
importQueueRef.current = items.slice(1)
|
||||
setImportReviewActive(true)
|
||||
openImportItem(items[0])
|
||||
@@ -288,6 +300,7 @@ export function useBookingEdits(options: BookingEditsOptions) {
|
||||
return
|
||||
}
|
||||
importQueueRef.current = []
|
||||
importSavedRef.current = null
|
||||
setImportReviewActive(false)
|
||||
setShowReservationModal(false); setEditingReservation(null); setReservationPrefill(null)
|
||||
setShowTransportModal(false); setEditingTransport(null); setTransportPrefill(null); setTransportModalDayId(null)
|
||||
|
||||
Reference in New Issue
Block a user