mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(bookings): a hotel booking's card shows check-in and check-out when only the stay has them
The edit form fell back to the linked stay's times, the cards read only the booking's metadata, so a hotel showed 15:00 and 11:00 when edited and no times in the list. The reservation list now carries the stay's check-in window and check-out, and the desktop facts and the phone card fall back to them. On the phone they come first, so a price or a seat cannot push them off the card.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-PLANNER-BKFACTS-001 to FE-PLANNER-BKFACTS-022
|
||||
// FE-PLANNER-BKFACTS-001 to FE-PLANNER-BKFACTS-024
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { buildDay, buildReservation } from '../../../../tests/helpers/factories';
|
||||
import type { ReservationEndpoint } from '../../../types';
|
||||
@@ -83,6 +83,26 @@ describe('bookingFacts: day', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('bookingFacts: hotel times', () => {
|
||||
it('FE-PLANNER-BKFACTS-023: a hotel without times of its own shows the stay's check-in and check-out', () => {
|
||||
const f = bookingFacts(buildReservation({
|
||||
type: 'hotel', accommodation_start_day_id: 701, accommodation_end_day_id: 702,
|
||||
accommodation_check_in: '15:00', accommodation_check_in_end: '18:00', accommodation_check_out: '11:00',
|
||||
}), ctx());
|
||||
expect(cell(f, 'reservations.meta.checkIn')).toBe('15:00 → 18:00');
|
||||
expect(cell(f, 'reservations.meta.checkOut')).toBe('11:00');
|
||||
});
|
||||
|
||||
it('FE-PLANNER-BKFACTS-024: the booking's own times win over the stay's', () => {
|
||||
const f = bookingFacts(buildReservation({
|
||||
type: 'hotel', metadata: JSON.stringify({ check_in_time: '14:00', check_out_time: '10:00' }),
|
||||
accommodation_check_in: '15:00', accommodation_check_in_end: '18:00', accommodation_check_out: '11:00',
|
||||
}), ctx());
|
||||
expect(cell(f, 'reservations.meta.checkIn')).toBe('14:00');
|
||||
expect(cell(f, 'reservations.meta.checkOut')).toBe('10:00');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bookingFacts: time', () => {
|
||||
it('FE-PLANNER-BKFACTS-008: start and end time with an arrow', () => {
|
||||
const f = bookingFacts(buildReservation({ reservation_time: '2025-06-01T09:05', reservation_end_time: '2025-06-01T11:30' }), ctx());
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Day, Reservation, ReservationEndpoint } from '../../../types'
|
||||
import { formatPriceText, formatTime, splitReservationDateTime } from '../../../utils/formatters'
|
||||
import { getFlightLegs, getTrainLegs, usesStationRoute } from '../../../utils/flightLegs'
|
||||
import { safeExternalHref } from '../../../utils/safeUrl'
|
||||
import { daySpan, parseMeta, type AssignmentLookupEntry } from './bookingsModel'
|
||||
import { daySpan, hotelStayTimes, parseMeta, type AssignmentLookupEntry } from './bookingsModel'
|
||||
|
||||
export interface FactsContext {
|
||||
t: (key: string, params?: Record<string, string | number>) => string
|
||||
@@ -105,10 +105,11 @@ export function bookingFacts(r: Reservation, c: FactsContext): BookingFacts {
|
||||
if (!c.hasLinkedCost && meta.price != null && meta.price !== '') {
|
||||
cells.push({ label: t('reservations.price'), value: formatPriceText(meta.price, meta.priceCurrency, c.tripCurrency, locale) })
|
||||
}
|
||||
if (meta.check_in_time) {
|
||||
cells.push({ label: t('reservations.meta.checkIn'), value: formatTime(meta.check_in_time, locale, timeFormat) + (meta.check_in_end_time ? ` → ${formatTime(meta.check_in_end_time, locale, timeFormat)}` : '') })
|
||||
const stay = hotelStayTimes(r, meta)
|
||||
if (stay.checkIn) {
|
||||
cells.push({ label: t('reservations.meta.checkIn'), value: formatTime(stay.checkIn, locale, timeFormat) + (stay.checkInEnd ? ` → ${formatTime(stay.checkInEnd, locale, timeFormat)}` : '') })
|
||||
}
|
||||
if (meta.check_out_time) cells.push({ label: t('reservations.meta.checkOut'), value: formatTime(meta.check_out_time, locale, timeFormat) })
|
||||
if (stay.checkOut) cells.push({ label: t('reservations.meta.checkOut'), value: formatTime(stay.checkOut, locale, timeFormat) })
|
||||
|
||||
// Per-segment codes (#1943), only on a real stopover booking.
|
||||
const legs = r.type === 'flight' ? getFlightLegs(r) : usesStationRoute(r.type) ? getTrainLegs(r) : []
|
||||
|
||||
@@ -103,6 +103,27 @@ export interface DaySpan {
|
||||
}
|
||||
|
||||
/** The days a booking sits on. A hotel reads its stay from the accommodation, which is the source of truth for the range (#1383). */
|
||||
/**
|
||||
* A hotel's check-in window and check-out: the booking's own metadata first,
|
||||
* then the stay it is linked to. Times often live only on the stay, and the
|
||||
* edit form already falls back the same way (reservationFormModel.ts).
|
||||
*/
|
||||
export function hotelStayTimes(
|
||||
r: Reservation,
|
||||
meta: { check_in_time?: string | null; check_in_end_time?: string | null; check_out_time?: string | null },
|
||||
): { checkIn: string | null; checkInEnd: string | null; checkOut: string | null } {
|
||||
if (r.type !== 'hotel') {
|
||||
return { checkIn: meta.check_in_time || null, checkInEnd: meta.check_in_end_time || null, checkOut: meta.check_out_time || null }
|
||||
}
|
||||
const checkIn = meta.check_in_time || r.accommodation_check_in || null
|
||||
return {
|
||||
checkIn,
|
||||
// A window end belongs to the check-in it came with.
|
||||
checkInEnd: meta.check_in_time ? meta.check_in_end_time || null : checkIn ? r.accommodation_check_in_end || null : null,
|
||||
checkOut: meta.check_out_time || r.accommodation_check_out || null,
|
||||
}
|
||||
}
|
||||
|
||||
export function daySpan(r: Reservation, days: Day[]): DaySpan {
|
||||
const byId = (id?: number | null) => (id != null ? days.find(d => d.id === id) : undefined)
|
||||
if (r.type === 'hotel' && (r.accommodation_start_day_id || r.accommodation_end_day_id)) {
|
||||
|
||||
Reference in New Issue
Block a user