fix(bookings): show the calendar date beside transport times

Tapping a transport in the compact Transports or Bookings list on the phone
opens the transport sheet, and its time boxes showed only the clock time. The
sheet named a date only in its subline, and only for a booking with no route
and no airline or number, so a flight or ferry could not be placed on a day
without unfolding the whole list. A transport holding only times (its date
lives on the linked trip day) had no date at all, and the desktop transport
detail dialog had the same gap: it read the date off reservation_time alone
and never named the arrival day of an overnight trip.

The dates now come from one helper, bookingDates(), which reads the booking's
own date, then the stop's local date, then the linked day's date, the rule
bookingFacts already used and now shares. The phone sheet prints the date
above each time (a leg opened from its row uses its own days); when no time
box carries a date, because no time is entered yet or the live flight card
stands in their place, the subline names the day instead. The desktop dialog
names the day, or both days of an overnight trip in reading order, in the
user's locale.

Closes #3122
This commit is contained in:
Maurice
2026-11-18 16:52:04 +01:00
parent 684a3bf5f5
commit 40f9c020bb
7 changed files with 193 additions and 22 deletions
@@ -16,7 +16,7 @@ import { useSearchParams } from 'react-router'
import { isTransportReservationType } from '@trek/shared'
import { useBookingLink } from '../../../../hooks/useBookingLink'
import { bookingFacts, stayStats } from '../../../../components/Planner/bookings/bookingFacts'
import { parseMeta } from '../../../../components/Planner/bookings/bookingsModel'
import { bookingDates, parseMeta } from '../../../../components/Planner/bookings/bookingsModel'
import { ActionCircle, Eyebrow, INNER_CLS, StatBox, TileHeader, displayTime } from './MTripSheetUi'
import { CardFiles } from '../tabs/MReservationCardParts'
import { downloadAttachment, openAttachment } from '../../../../components/Planner/bookings/openAttachment'
@@ -131,9 +131,10 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
const canEdit = liveRes != null && (isTransportReservationType(liveRes.type) ? canEditDays : canEditBookings)
const ResIcon = RES_ICONS[res.type as keyof typeof RES_ICONS] || RES_ICONS.other
const from = (res.endpoints || []).find(e => e.role === 'from')
const to = (res.endpoints || []).find(e => e.role === 'to')
const { date, time: startTime } = splitReservationDateTime(res.reservation_time)
const endpoints = res.endpoints || []
const from = endpoints.find(e => e.role === 'from')
const to = endpoints.find(e => e.role === 'to')
const { time: startTime } = splitReservationDateTime(res.reservation_time)
const { time: endTime } = splitReservationDateTime(res.reservation_end_time)
const bookingDepTime = from?.local_time || startTime
const bookingArrTime = to?.local_time || endTime
@@ -151,6 +152,12 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
const arrTime = leg ? leg.arr_time || '' : bookingArrTime
const depLabel = (leg ? leg.from : from?.name) || t('reservations.time')
const arrLabel = (leg ? leg.to : to?.name) || t('reservations.time')
// The calendar date each time falls on (#3122): a time alone cannot be placed
// when the sheet is opened from a compact list that shows nothing else.
const legDate = (dayId?: number | null) => (dayId != null ? planner.days.find(d => d.id === dayId)?.date : null) || null
const dates = leg ? { start: legDate(leg.dep_day_id), end: legDate(leg.arr_day_id) } : bookingDates(res, planner.days)
const depDate = dates.start ? bookingDayLabel(dates.start, locale) : null
const arrDate = dates.end ? bookingDayLabel(dates.end, locale) : null
const subParts: string[] = []
const airline = leg ? legDetail.airline : meta.airline
@@ -161,7 +168,6 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
if (trainNumber) subParts.push(trainNumber)
if (leg && (leg.from || leg.to)) subParts.push(flowText([leg.from, leg.to].filter((n): n is string => !!n)))
else if (from?.name && to?.name) subParts.push(flowText([from.name, to.name]))
else if (date) subParts.push(bookingDayLabel(date, locale))
// A flight's legs carry no seat or platform of their own, so those stay the booking's.
const seat = leg && !isFlight ? legDetail.seat : meta.seat
@@ -170,6 +176,11 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
// Opened from one leg's row, only that leg's live card; from the booking, every followed leg.
const shownLive = leg ? liveLegs.filter(l => l.leg_index === payload.legIndex) : liveLegs
const showTimes = shownLive.length === 0
// A shown time box carries its own date. Without one (no time entered yet, or the
// live card in its place) the subline names the day, route and airline or not.
const datedTime = showTimes && ((depTime && depDate) || (arrTime && arrDate))
if (depDate && !datedTime) subParts.push(depDate)
const resFiles = filesFor(res, planner.files || [])
@@ -263,13 +274,13 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
))}
{/* ── Times / seat stats (the live card already shows the times) ── */}
{hotelStats.length === 0 && ((shownLive.length === 0 && (depTime || arrTime)) || seat || platform) && (
{hotelStats.length === 0 && ((showTimes && (depTime || arrTime)) || seat || platform) && (
<div className="mt-[14px] flex gap-[6px]">
{shownLive.length === 0 && depTime && (
<StatBox value={displayTime(depTime, locale, timeFormat)} label={depLabel} />
{showTimes && depTime && (
<StatBox caption={depDate} value={displayTime(depTime, locale, timeFormat)} label={depLabel} />
)}
{shownLive.length === 0 && arrTime && (
<StatBox value={displayTime(arrTime, locale, timeFormat)} label={arrLabel} />
{showTimes && arrTime && (
<StatBox caption={arrDate} value={displayTime(arrTime, locale, timeFormat)} label={arrLabel} />
)}
{platform && <StatBox value={platform} label={t('reservations.meta.platform')} />}
{seat && <StatBox value={seat} label={t('reservations.meta.seat')} />}
@@ -121,6 +121,8 @@ export function TileHeader({ icon, title, sub, subWrap = false, onClose, closeLa
interface StatBoxProps {
value: ReactNode
label: ReactNode
/** A line above the value, such as the calendar date a time falls on. */
caption?: ReactNode
blurred?: boolean
onClick?: () => void
/** Colours the label, so a check-in or check-out time carries its own state. */
@@ -133,10 +135,11 @@ const LABEL_TONE: Record<NonNullable<StatBoxProps['labelTone']>, string> = {
}
/** Small stat box (check-in / times / code): value 700 tabular over a faint Geist label. */
export function StatBox({ value, label, blurred = false, onClick, labelTone }: StatBoxProps) {
export function StatBox({ value, label, caption, blurred = false, onClick, labelTone }: StatBoxProps) {
const box = 'min-w-0 flex-1 rounded-[10px] bg-[color:var(--m-ic)] px-[9px] py-[7px] text-center'
const inner = (
<>
{caption && <div className="truncate font-geist text-caption leading-tight text-m-muted">{caption}</div>}
<div
className={`truncate text-[0.8125rem] font-bold tabular-nums leading-tight ${blurred ? 'blur-[4px] select-none' : ''}`}
>