mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
fix(booking-import): stop writing an unreadable type down as a hotel (#2076)
When neither the keyword table nor the model produced a type, the router wrote "hotel" and cast whatever string it got to FlatType without checking it. A hotel is a booking type, so a ferry voucher imported from the Transport tab opened the booking form, which offers six chips and not one transport among them, and "other" was the only honest pick left. An unrecognised string got through the cast too and then vanished silently in nuExtractToKiReservations. The type is validated against FLAT_TYPES now. When it cannot be read the item is still extracted with the lodging shape so it survives mapping, but it says so, and the tie-breaker #2080 added finally has something to fire on: isUnplaceableItem only ever matched a type outside both form's vocabularies, and the server can only emit its own eight, so on a real document it never matched at all. The tab travels with the job instead of sitting in component state. The parse deliberately outlives navigation and reload and the review is triggered by the global widget on any page, so by the time it ran the state had remounted back to its default and the context was gone.
This commit is contained in:
@@ -10,6 +10,9 @@ interface BookingImportModalProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
tripId: number
|
||||
/** The tab this import was started from, carried into the job so the review
|
||||
* can pick the right form for an item whose type had to be guessed (#2076). */
|
||||
kind?: 'transports' | 'bookings'
|
||||
}
|
||||
|
||||
const ACCEPTED_EXTS = ['.eml', '.pdf', '.pkpass', '.html', '.htm', '.txt']
|
||||
@@ -22,7 +25,7 @@ const MAX_FILES = 5
|
||||
* (progress over the WebSocket). When it finishes, the trip page opens the per-item
|
||||
* review flow — so the user can navigate and keep editing while it works.
|
||||
*/
|
||||
export default function BookingImportModal({ isOpen, onClose, tripId }: BookingImportModalProps) {
|
||||
export default function BookingImportModal({ isOpen, onClose, tripId, kind }: BookingImportModalProps) {
|
||||
const { t } = useTranslation()
|
||||
const addTask = useBackgroundTasksStore((s) => s.addTask)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
@@ -100,7 +103,7 @@ export default function BookingImportModal({ isOpen, onClose, tripId }: BookingI
|
||||
// Keep the uploaded files so the review can attach each source document to its booking —
|
||||
// in memory for the immediate path, and in IndexedDB so it survives a reload mid-parse.
|
||||
await saveImportFiles(jobId, files)
|
||||
addTask({ id: jobId, tripId: String(tripId), label: files.map((f) => f.name).join(', '), total: files.length, files, mode })
|
||||
addTask({ id: jobId, tripId: String(tripId), label: files.map((f) => f.name).join(', '), total: files.length, files, mode, kind })
|
||||
handleClose()
|
||||
} catch (err: any) {
|
||||
setError(err?.response?.data?.error ?? t('reservations.import.error'))
|
||||
|
||||
@@ -52,9 +52,16 @@ export function isTransportItem(item: BookingImportPreviewItem): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Neither form can express this type, so neither is obviously right. The tab the
|
||||
* user started the import from breaks the tie (#2076).
|
||||
* Neither form is obviously right, so the tab the user started the import from
|
||||
* breaks the tie (#2076).
|
||||
*
|
||||
* Two cases. A type neither form can express, and a type the extractor filled in
|
||||
* rather than read. The second is the one that actually occurs: the server can
|
||||
* only ever emit its eight known types, so the first branch never fires on a real
|
||||
* document, and a ferry voucher the model could not classify arrived as a
|
||||
* placeholder 'hotel' with no way to tell it from a real one.
|
||||
*/
|
||||
export function isUnplaceableItem(item: BookingImportPreviewItem): boolean {
|
||||
if (item.type_guessed === true) return true
|
||||
return !TRANSPORT_TYPES.has(item.type) && !BOOKING_TYPES.has(item.type)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user