feat(mobile): icon-only action rows in the transport and booking sheets (#2585)

The transport sheet's row wrapped once a ticket and the wallet were there.
Its actions are icons now, named by their labels, and the attachments sit in
their own rows with a download, like the transports list. The wallet is a
black circle, beside the close button in the booking editor. A failed
download on the phone now says so.
This commit is contained in:
Maurice
2026-11-13 10:49:30 +01:00
parent 5137bcb86a
commit a08d4b944e
38 changed files with 103 additions and 95 deletions
@@ -85,6 +85,14 @@ describe('useReservationCard', () => {
expect(openFile).toHaveBeenCalledTimes(1);
});
it('FE-PLANNER-RESLISTFILTER-008b: a download that fails says so with a toast', async () => {
vi.mocked(downloadFile).mockRejectedValueOnce(new Error('offline'));
const opts = host();
const { result } = renderHook(() => useReservationCard(ann, opts));
result.current.downloadFile(file);
await vi.waitFor(() => expect(opts.toast.error).toHaveBeenCalledWith('files.downloadError'));
});
it('FE-PLANNER-RESLISTFILTER-009: the card knows whether deleting it takes a linked expense along (#2604)', () => {
resetAllStores();
seedStore(useTripStore, { budgetItems: [buildBudgetItem({ id: 1, reservation_id: 10 } as never)] });
@@ -19,9 +19,10 @@ export interface ReservationCardHost {
* opening: its booking code blurred until tapped while the "Blur booking codes"
* preference is on (off, the code is plain and has no toggle), the delete
* behind a question with a toast when it fails, and its attached files, which
* open or download from their own row. A file that cannot be opened or saved
* stays silent here; the desktop panel toasts it. The delete question names a
* linked expense, which goes with the booking.
* open or download from their own row. A download that fails says so with a
* toast, since a save button that does nothing reads as broken; opening stays
* silent as it always was. The delete question names a linked expense, which
* goes with the booking.
*/
export function useReservationCard(res: Reservation, host: ReservationCardHost) {
const blurCodes = host.settings.blur_booking_codes;
@@ -45,6 +46,6 @@ export function useReservationCard(res: Reservation, host: ReservationCardHost)
void confirmDelete();
},
openFile: (f: Attachment) => openAttachment(f),
downloadFile: (f: Attachment) => downloadAttachment(f),
downloadFile: (f: Attachment) => downloadAttachment(f, () => host.toast.error(host.t('files.downloadError'))),
};
}
@@ -66,9 +66,9 @@ describe('MWalletButton', () => {
wallet.addGoogle.mockResolvedValue('added');
const onError = vi.fn();
render(<MWalletButton tripId={42} reservationId={7} onError={onError} />);
// The label is short, the accessible name says which wallet.
expect(screen.getByRole('button')).toHaveTextContent(/^Wallet$/);
expect(screen.getByRole('button', { name: /Google Wallet/ })).toBeInTheDocument();
// An icon only: the name and the tooltip say which wallet.
expect(screen.getByRole('button')).toHaveTextContent('');
expect(screen.getByRole('button', { name: /Google Wallet/ })).toHaveAttribute('title', 'Add to Google Wallet');
fireEvent.click(screen.getByRole('button'));
await waitFor(() => expect(wallet.addGoogle).toHaveBeenCalledWith(42, 7, expect.any(String)));
expect(wallet.add).not.toHaveBeenCalled();
+21 -7
View File
@@ -17,15 +17,24 @@ interface MWalletButtonProps {
className?: string;
/** Shown when the pass could not be made (a toast in the sheet that hosts the button). */
onError: (message: string) => void;
/** 34px beside a sheet header's close button instead of 40px in an action row. */
compact?: boolean;
}
/**
* "Add to Apple Wallet" on a booking in the iOS app (feature wallet), "Add to
* Google Wallet" in the Android app (feature googleWallet): the booking becomes a
* TREK pass that shows up around its time and place. Black like both stores' own
* badges, so it reads as the wallet at a glance.
* TREK pass that shows up around its time and place. A black circle like both
* stores' own badges, so it reads as the wallet at a glance; the phone's action
* rows are icons only, the name is in the label and tooltip.
*/
export default function MWalletButton({ tripId, reservationId, onError, className }: MWalletButtonProps) {
export default function MWalletButton({
tripId,
reservationId,
onError,
className,
compact = false,
}: MWalletButtonProps) {
const { t, language } = useTranslation();
// Re-renders once the app binary has said what it can do.
useNativeCapabilities();
@@ -51,17 +60,22 @@ export default function MWalletButton({ tripId, reservationId, onError, classNam
}
};
const label = t(wallet === 'google' ? 'reservations.wallet.addGoogle' : 'reservations.wallet.add');
const button = (
<button
type="button"
onClick={() => void add()}
disabled={busy}
aria-busy={busy}
aria-label={t(wallet === 'google' ? 'reservations.wallet.addGoogle' : 'reservations.wallet.add')}
className="flex items-center gap-[6px] rounded-full bg-black px-3 py-[7px] text-[length:calc(12px*var(--fs-scale-body,1))] font-semibold text-white transition-transform active:scale-[.97] disabled:opacity-70" // theme-lint-disable: the wallets' badges are black in either theme
aria-label={label}
title={label}
className={`flex ${compact ? 'h-[34px] w-[34px]' : 'h-10 w-10'} flex-none items-center justify-center rounded-full bg-black text-white transition-transform active:scale-[.97] disabled:opacity-70 dark:ring-1 dark:ring-white/25`} // theme-lint-disable: the wallets' badges are black in either theme
>
{busy ? <Loader2 size={13} className="animate-spin" /> : <Wallet size={13} strokeWidth={2} />}
{t('reservations.wallet.short')}
{busy ? (
<Loader2 size={compact ? 15 : 16} className="animate-spin" />
) : (
<Wallet size={compact ? 15 : 16} strokeWidth={2} />
)}
</button>
);
return className ? <div className={className}>{button}</div> : button;
@@ -185,13 +185,13 @@ export default function MReservationSheet({ planner, onOpenExpense }: MReservati
<FormSheetHeader
icon={Ticket}
title={res ? t('reservations.editTitle') : t('reservations.newTitle')}
// A saved booking goes into the phone's wallet (in the iOS and Android apps).
trailing={<MWalletButton tripId={tripId} reservationId={savedId(res)} onError={toast.error} compact />}
onClose={handleClose}
closeLabel={t('common.close')}
/>
<FormSheetBody>
{/* A saved booking goes into Apple Wallet (iOS app only). */}
<MWalletButton tripId={tripId} reservationId={savedId(res)} onError={toast.error} className="mb-1 mt-2 flex" />
{/* BOOKING TYPE */}
<Eyebrow className="mb-[6px] mt-2 uppercase">{t('reservations.bookingType')}</Eyebrow>
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from 'react'
import { ArrowRight, Footprints, Paperclip, Pencil, Route as RouteIcon, Trash2 } from 'lucide-react'
import { ArrowRight, Footprints, Pencil, Route as RouteIcon, Trash2 } from 'lucide-react'
import MSheet from '../../../components/MSheet'
import MWalletButton from '../../../components/MWalletButton'
import type { MTripSheetsProps } from '../MTripShell'
@@ -8,7 +8,6 @@ import { useSettingsStore } from '../../../../store/settingsStore'
import { RES_ICONS } from '../../../../components/Planner/DayPlanSidebar.constants'
import { splitReservationDateTime } from '../../../../utils/formatters'
import { getFlightLegs, getTrainLegs, usesStationRoute, type FlightLeg, type TrainLeg } from '../../../../utils/flightLegs'
import { openFile } from '../../../../utils/fileDownload'
import { runsOnDay } from '../../../../utils/reservationRoutes'
import { filesFor } from '../../../../utils/reservationFiles'
import { bookingDayLabel, segmentCodeLabel } from '../../../../components/Planner/transportDetailModel'
@@ -18,7 +17,9 @@ 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 { Eyebrow, INNER_CLS, StatBox, TileHeader, displayTime } from './MTripSheetUi'
import { ActionCircle, Eyebrow, INNER_CLS, StatBox, TileHeader, displayTime } from './MTripSheetUi'
import { CardFiles } from '../tabs/MReservationCardParts'
import { downloadAttachment, openAttachment } from '../../../../components/Planner/bookings/openAttachment'
import { flowText } from '../../../../utils/flowText'
interface TransportSheetPayload {
@@ -342,50 +343,31 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
</>
)}
{/* ── Actions ── */}
<div className="mt-3 flex flex-wrap items-center gap-[7px]">
<button
type="button"
onClick={showOnMap}
aria-pressed={onMap}
className={`flex items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold ${
onMap ? 'bg-m-act text-m-actfg' : INNER_CLS
}`}
>
<RouteIcon size={13} strokeWidth={2} />
{t('mobileTrip.onMap')}
</button>
{/* ── Files: their own rows, so a long name never pushes the actions onto a second line ── */}
<CardFiles
files={resFiles}
card={{
openFile: openAttachment,
downloadFile: f => downloadAttachment(f, () => planner.toast.error(t('files.downloadError'))),
}}
t={t}
/>
{/* ── Actions: icons only, the names are their labels ── */}
<div className="mt-[14px] flex items-center gap-[7px]">
<ActionCircle onClick={showOnMap} label={t('mobileTrip.onMap')} pressed={onMap}>
<RouteIcon size={15} strokeWidth={2} />
</ActionCircle>
<MWalletButton tripId={planner.tripId} reservationId={payload.reservationId} onError={planner.toast.error} />
{resFiles.map(f => (
<button
key={f.id}
type="button"
onClick={() => openFile(f.url, f.original_name)}
className={`flex max-w-[150px] items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold ${INNER_CLS}`}
>
<Paperclip size={13} strokeWidth={2} className="flex-none" />
<span dir="auto" className="truncate">{f.original_name}</span>
</button>
))}
{canEdit && (
<button
type="button"
onClick={editTransport}
className="ms-auto flex items-center gap-[5px] rounded-full bg-m-act px-3 py-[7px] text-[0.75rem] font-semibold text-m-actfg"
>
<Pencil size={13} strokeWidth={2} />
{t('common.edit')}
</button>
<ActionCircle onClick={editTransport} label={t('common.edit')} primary className="ms-auto">
<Pencil size={15} strokeWidth={2} />
</ActionCircle>
)}
{canEdit && (
<button
type="button"
onClick={deleteTransport}
aria-label={t('common.delete')}
className={`flex items-center rounded-full px-3 py-[7px] text-[color:var(--m-st-danger)] ${INNER_CLS}`}
>
<Trash2 size={14} strokeWidth={2} />
</button>
<ActionCircle onClick={deleteTransport} label={t('common.delete')} danger>
<Trash2 size={15} strokeWidth={2} />
</ActionCircle>
)}
</div>
</div>
@@ -160,23 +160,29 @@ interface ActionCircleProps {
label: string
primary?: boolean
danger?: boolean
/** A toggle (shown on the map): announced as pressed and filled while on. */
pressed?: boolean
className?: string
children: ReactNode
/** For callers that anchor a popup to the button. React 19 passes it through. */
ref?: Ref<HTMLButtonElement>
}
/** 38px round action button of the inspector footer rows. */
export function ActionCircle({ onClick, label, primary = false, danger = false, className = '', children, ref }: ActionCircleProps) {
/**
* 40px round action button of the sheets' action rows. The rows hold icons
* only, so a phone never wraps them; the name is the label and the tooltip.
*/
export function ActionCircle({ onClick, label, primary = false, danger = false, pressed, className = '', children, ref }: ActionCircleProps) {
return (
<button
ref={ref}
type="button"
onClick={onClick}
aria-label={label}
aria-pressed={pressed}
title={label}
className={`flex h-[38px] w-[38px] flex-none items-center justify-center rounded-full ${
primary
className={`flex h-10 w-10 flex-none items-center justify-center rounded-full ${
primary || pressed
? 'bg-m-act text-m-actfg'
: `border border-[color:var(--m-gbr)] bg-[color:var(--m-ic)] ${danger ? 'text-[color:var(--m-st-danger)]' : 'text-m-ink'}`
} ${className}`}
@@ -64,12 +64,14 @@ interface FormSheetHeaderProps {
subtitle?: ReactNode
/** Replaces the icon tile, e.g. a back button on the import sub-steps. */
leading?: ReactNode
/** A 34px action before the close button (the booking's Wallet pass). */
trailing?: ReactNode
onClose: () => void
closeLabel: string
}
/** Form-sheet header: optional tile, 17px/700 title, 34px close. No hairline. */
export function FormSheetHeader({ icon: Icon, title, subtitle, leading, onClose, closeLabel }: FormSheetHeaderProps) {
export function FormSheetHeader({ icon: Icon, title, subtitle, leading, trailing, onClose, closeLabel }: FormSheetHeaderProps) {
return (
<div className="m-fs-head flex flex-none items-center gap-3 px-[18px] pb-2 pt-4">
{leading}
@@ -84,6 +86,7 @@ export function FormSheetHeader({ icon: Icon, title, subtitle, leading, onClose,
<div className="line-clamp-2 break-words text-[1.0625rem] font-bold leading-tight text-m-ink">{title}</div>
{subtitle && <div className="truncate font-geist text-[0.71875rem] text-m-muted">{subtitle}</div>}
</div>
{trailing}
<MIconBtn ariaLabel={closeLabel} onClick={onClose} variant="neutral" size={34} className="m-fs-close">
<X size={15} strokeWidth={2.2} />
</MIconBtn>
@@ -168,7 +168,15 @@ export function CardNotes({ notes }: { notes: string | null | undefined }) {
* can hold two real buttons: the name opens the file, the icon at the end saves
* it (a PDF ticket that only opens in a viewer cannot be kept otherwise).
*/
export function CardFiles({ files, card, t }: { files: ReturnType<typeof filesFor>; card: CardState; t: T }) {
export function CardFiles({
files,
card,
t,
}: {
files: ReturnType<typeof filesFor>;
card: Pick<CardState, 'openFile' | 'downloadFile'>;
t: T;
}) {
if (files.length === 0) return null;
return (
<div className="mt-2">