feat(roadtrip): hire car desks, bookings under stops, the ride as one block

A hire car is no seam, but its desks are where the drive starts and ends: the
pick-up opens its day when nothing timed comes first, the return closes the
day it is handed back on, the road runs through both and the range budget
starts from a full tank at the pick-up. The return is only placed when the
booking names a return day and a located return desk.

A table, tickets or a tour on the day hang under the stop they are pinned to
or booked at as chips that open the booking; one for no stop is listed under
the day. A ride that leaves and lands on the same day is one block on the
rail and in the phone chain, not two terminal rows and a band. Both shells
read the same helpers (carrierRide, stopBookings, roadtripRowModel).

Server reads car bookings into the plan context; the MCP descriptions say so.
The pt-BR locale had the three ride strings in Breton, fixed alongside.

Refs #2428
This commit is contained in:
Maurice
2026-09-21 17:05:42 +02:00
parent 0b4230ff4c
commit bdb031a1e9
43 changed files with 1069 additions and 189 deletions
@@ -4,14 +4,15 @@ import MDancingTrek from '../../../components/MDancingTrek'
import MIconBtn from '../../../components/MIconBtn'
import { formatDurationShort, serviceColor } from '../../../../components/Roadtrip/roadtripModel'
import { carrierIcon, rideText, terminalLine } from '../../../../components/Roadtrip/carrierRide'
import { bookingClock, bookingIcon } from '../../../../components/Roadtrip/stopBookings'
import { STOP_KIND_BY_KEY } from '../../../../components/Roadtrip/stopKinds'
import { formatDistance } from '../../../../utils/units'
import { formatClockTime } from '../../../../utils/formatters'
import type { StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
import type { RoadtripRow, StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
import type { RefuelSearch } from '../../../../components/Roadtrip/useRefuelSearch'
import { REFUEL_EMPTY_KEY, REFUEL_WORDS, refuelBandState, type RefuelCandidate } from '../../../../components/Roadtrip/refuelSuggestion'
import type { CarrierTerminal, DistanceUnit, RouteSegment, ScheduleWarning } from '@trek/shared/roadtrip'
import type { TranslationFn } from '../../../../types'
import type { DistanceUnit, RouteSegment, ScheduleWarning } from '@trek/shared/roadtrip'
import type { Reservation, TranslationFn } from '../../../../types'
/**
* The four row types of the mobile drive chain, plus the two bands that interrupt it.
@@ -186,36 +187,101 @@ const LEG_ICONS: Record<string, typeof CarFront> = {
cycling: Bike,
}
/** One end of a ride inside its block: name, code, the timetable line, the clock. */
function RideEnd({ row, chrome }: { row: StopRow; chrome: RowChrome }) {
const carrier = row.stop.carrier!
const line = terminalLine(carrier, chrome.t, chrome.is12h)
return (
<span className="flex items-center gap-[8px]">
<span className="min-w-0 flex-1">
<span className="flex min-w-0 items-center gap-[6px]">
<span className="line-clamp-2 text-[0.875rem] font-semibold leading-[1.25] text-m-ink">{row.stop.name}</span>
{carrier.code && <span className="flex-none font-geist text-[0.65625rem] font-medium text-m-faint">{carrier.code}</span>}
</span>
{line && <span className="mt-[2px] block font-geist text-[0.65625rem] font-medium text-m-muted">{line}</span>}
</span>
{row.time && (
<span dir="ltr" className={`whitespace-nowrap text-[0.8125rem] tabular-nums ${row.pinned ? 'font-semibold text-m-ink' : 'font-medium text-m-faint'}`}>
{formatClockTime(row.time, chrome.is12h)}
</span>
)}
</span>
)
}
/**
* The ride between two terminals, where a leg pill would be (#2428): the booking and its
* minutes, no distance and no other ways of driving it. The pill is the tap target and
* opens the booking, the same sheet the map's endpoint badge opens.
* A ride that leaves and lands on the day, as one block in the chain (#2428): the
* booking and its minutes at the top, the terminal it leaves from, the terminal it lands
* at. One block on one disc, because it is one thing, and three rows read as three
* places the day went to. The block is the tap target and opens the booking, the same
* sheet the map's endpoint badge opens.
*/
export function RtRideRow({ carrier, seg, onOpen }: {
carrier: CarrierTerminal
seg: RouteSegment | undefined
export function RtRideRow({ row, chrome, onOpen }: {
row: Extract<RoadtripRow, { kind: 'ride' }>
chrome: RowChrome
onOpen?: () => void
}) {
const Icon = carrierIcon(carrier.type)
const Icon = carrierIcon(row.carrier.type)
const body = (
<>
<Icon size={14} strokeWidth={2} className="flex-none text-m-muted" aria-hidden="true" />
<span className="truncate text-[0.75rem] font-semibold tabular-nums text-m-ink">{rideText(carrier, seg)}</span>
<span className="flex items-center gap-[6px] text-m-muted">
<Icon size={12} strokeWidth={2} className="flex-none" aria-hidden="true" />
<span className="truncate font-geist text-[0.65625rem] font-semibold uppercase tracking-[0.06em]">{rideText(row.carrier, row.seg)}</span>
</span>
<RideEnd row={row.departure} chrome={chrome} />
<RideEnd row={row.arrival} chrome={chrome} />
</>
)
const cls = 'my-1 flex min-w-0 flex-col gap-[7px] rounded-[16px] bg-[color:var(--m-ic)] px-[12px] py-[9px] text-start'
return (
<div className="grid items-center gap-x-[10px]" style={{ gridTemplateColumns: '34px 1fr auto' }}>
<span className="flex min-h-[40px] flex-col items-center" aria-hidden="true">
<span className="w-[2px] flex-1" style={{ backgroundImage: 'repeating-linear-gradient(var(--m-conn) 0 4px, transparent 4px 8px)' }} />
<div className="grid items-center gap-x-[10px] py-1" style={{ gridTemplateColumns: '34px 1fr' }}>
<span className="flex justify-center">
<span className="grid h-[30px] w-[30px] shrink-0 place-items-center rounded-full bg-[color:var(--m-ic)] text-m-ink">
<Icon size={15} strokeWidth={2.1} aria-hidden="true" />
</span>
</span>
{onOpen ? (
<button type="button" onClick={onOpen} className="my-1.5 flex min-w-0 items-center gap-[7px] rounded-[13px] bg-[color:var(--m-ic)] px-[11px] py-[7px] text-start">
{body}
</button>
<button type="button" onClick={onOpen} className={cls}>{body}</button>
) : (
<span className="my-1.5 flex min-w-0 items-center gap-[7px] rounded-[13px] bg-[color:var(--m-ic)] px-[11px] py-[7px]">{body}</span>
<span className={cls}>{body}</span>
)}
<span className="h-10 w-10 flex-none" aria-hidden="true" />
</div>
)
}
/**
* The bookings a stop carries, under its row (#2428): the table, the tickets, the tour,
* each a chip with the booking panel's icon, its name and the clock it starts at. Chips
* because a booking is a fact about the stop and not a stop of its own. Each opens its
* booking; without `onOpen` they are plain.
*/
export function RtBookingChips({ bookings, chrome, onOpen }: {
bookings: Reservation[]
chrome: RowChrome
onOpen?: (reservation: Reservation) => void
}) {
return (
<div className="grid gap-x-[10px] pb-2" style={{ gridTemplateColumns: '34px 1fr' }}>
<span aria-hidden="true" />
<span className="flex flex-wrap gap-[6px]">
{bookings.map(r => {
const Icon = bookingIcon(r.type)
const clock = bookingClock(r)
const body = (
<>
<Icon size={11} strokeWidth={2} className="flex-none text-m-muted" aria-hidden="true" />
<span className="min-w-0 truncate text-[0.75rem] font-medium text-m-ink">{r.title}</span>
{clock && <span className="flex-none font-geist text-[0.65625rem] tabular-nums text-m-faint">{formatClockTime(clock, chrome.is12h)}</span>}
</>
)
const cls = 'inline-flex h-[28px] max-w-full items-center gap-[5px] rounded-full border border-[color:var(--m-inbr)] bg-[color:var(--m-inner)] px-[10px]'
return onOpen ? (
<button key={r.id} type="button" onClick={() => onOpen(r)} className={`${cls} text-start`}>{body}</button>
) : (
<span key={r.id} className={cls}>{body}</span>
)
})}
</span>
</div>
)
}
@@ -1,4 +1,4 @@
import { useRef } from 'react'
import { Fragment, useMemo, useRef } from 'react'
import { AlertTriangle, MapPin, Navigation } from 'lucide-react'
import { useMPlanDaySwipe } from '../plan/useMPlanDaySwipe'
import { showStopOnMap, useMRoadtrip } from './useMRoadtrip'
@@ -6,7 +6,7 @@ import { useMRtCorridor } from './useMRtCorridor'
import { useMRtAlternatives } from './useMRtAlternatives'
import MRtCorridorBar from './MRtCorridorBar'
import MRtAlternativesBar from './MRtAlternativesBar'
import { RtAutoRow, RtDryRow, RtLegRow, RtRideRow, RtSpillRow, RtStopRow, type RowChrome } from './MRoadtripRows'
import { RtAutoRow, RtBookingChips, RtDryRow, RtLegRow, RtRideRow, RtSpillRow, RtStopRow, type RowChrome } from './MRoadtripRows'
import MBadge from '../../../components/MBadge'
import MDancingTrek from '../../../components/MDancingTrek'
import { formatDurationShort } from '../../../../components/Roadtrip/roadtripModel'
@@ -17,6 +17,8 @@ import { formatClockTime } from '../../../../utils/formatters'
import { isRtlLanguage } from '../../../../i18n'
import type { MTripTabPanelProps } from '../MTripShell'
import { legReroutable, type StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
import { dayBookings } from '../../../../components/Roadtrip/stopBookings'
import type { Reservation } from '../../../../types'
/**
* The road trip tab: one day of the drive, as a chain or on the map.
@@ -82,6 +84,26 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
else shell.openSheet('rtstop', { dayId: row.stop.ownerDayId, assignmentId: row.stop.assignmentId })
}
// The bookings under the stage's stops and the ones the stage has for no stop, keyed
// by the stop's assignment because the rows carry no index. Opened the way the place
// sheet opens its linked bookings: a transport in its sheet, anything else in its
// editor, and only for somebody allowed to.
const bookings = useMemo(() => {
const byIndex = stage ? dayBookings(stage, planner.reservations) : null
const atStop = new Map<number, Reservation[]>()
if (stage && byIndex) for (const [i, list] of byIndex.atStop) atStop.set(stage.stops[i]!.assignmentId, list)
return { atStop, loose: byIndex?.loose ?? [] }
}, [stage, planner.reservations])
const openBooking = (res: Reservation) => {
if (planner.TRANSPORT_TYPES.has(res.type)) {
shell.openSheet('transport', { reservationId: res.id })
return
}
if (!planner.can('reservation_edit', planner.trip)) return
planner.setEditingReservation(res)
planner.setShowReservationModal(true)
}
// The search bar sits in the same band on both halves, at the same offset, so the
// list/map switch never moves it: it is one stage seen two ways, and a control that
// jumps between them is a control you have to find twice. The band and the margins
@@ -226,20 +248,23 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
<section className="mt-2.5 overflow-hidden rounded-[22px] border border-[color:var(--m-cbr)] bg-[color:var(--m-card)] px-3.5 pb-3 pt-1">
{rt.rows.map((row, i) => {
if (row.kind === 'stop') {
const chips = bookings.atStop.get(row.stop.assignmentId)
return (
<RtStopRow
key={`s${i}`}
row={row}
chrome={chrome}
onOpen={() => openStop(row)}
onPickKind={canEditPlaces && !row.stop.carrier
? () => shell.openSheet('rtkind', {
placeId: row.stop.placeId,
stopType: row.stop.stopType ?? null,
name: row.stop.name,
})
: undefined}
/>
<Fragment key={`s${i}`}>
<RtStopRow
row={row}
chrome={chrome}
onOpen={() => openStop(row)}
onPickKind={canEditPlaces && !row.stop.carrier
? () => shell.openSheet('rtkind', {
placeId: row.stop.placeId,
stopType: row.stop.stopType ?? null,
name: row.stop.name,
})
: undefined}
/>
{chips && <RtBookingChips bookings={chips} chrome={chrome} onOpen={openBooking} />}
</Fragment>
)
}
if (row.kind === 'leg') {
@@ -259,7 +284,7 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
)
}
if (row.kind === 'ride') {
return <RtRideRow key={`r${i}`} carrier={row.carrier} seg={row.seg} onOpen={() => shell.openSheet('transport', { reservationId: row.carrier.reservationId })} />
return <RtRideRow key={`r${i}`} row={row} chrome={chrome} onOpen={() => shell.openSheet('transport', { reservationId: row.carrier.reservationId })} />
}
if (row.kind === 'auto') return <RtAutoRow key={`a${i}`} phase={row.phase} time={row.time} chrome={chrome} />
if (row.kind === 'spill') {
@@ -284,6 +309,15 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
/>
)
})}
{bookings.loose.length > 0 && (
<div className="mt-1">
<div className="grid gap-x-[10px]" style={{ gridTemplateColumns: '34px 1fr' }}>
<span aria-hidden="true" />
<span className="mb-[6px] block font-geist text-[0.65625rem] font-semibold uppercase tracking-[0.08em] text-m-faint">{t('roadtrip.bookings.loose')}</span>
</div>
<RtBookingChips bookings={bookings.loose} chrome={chrome} onOpen={openBooking} />
</div>
)}
</section>
</>
)}