mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
fix(mobile): a booking opens its detail sheet first, as a transport and the desktop do; Wallet and Map buttons read short
Bookings in the Bookings tab, the day sheet, a place's sheet and the road trip opened their editor straight away, while a transport showed its details with a pencil to edit. Every booking now opens the same detail sheet; its edit and delete follow the booking's own permission (reservation_edit for a stay, a table or a ticket, day_edit for a transport). Notes keep opening for editing, as on the desktop. The wallet button reads "Wallet" (its accessible name still says which one), and "On map" reads "Map" in every language.
This commit is contained in:
@@ -61,12 +61,14 @@ describe('MWalletButton', () => {
|
||||
await waitFor(() => expect(onError).toHaveBeenLastCalledWith(expect.stringMatching(/could not be made/i)));
|
||||
});
|
||||
|
||||
it('on Android adds the booking to Google Wallet, under its own name', async () => {
|
||||
it('on Android adds the booking to Google Wallet, under its own name for screen readers', async () => {
|
||||
wallet.kind = 'google';
|
||||
wallet.addGoogle.mockResolvedValue('added');
|
||||
const onError = vi.fn();
|
||||
render(<MWalletButton tripId={42} reservationId={7} onError={onError} />);
|
||||
expect(screen.getByRole('button')).toHaveTextContent(/Google Wallet/);
|
||||
// The label is short, the accessible name says which wallet.
|
||||
expect(screen.getByRole('button')).toHaveTextContent(/^Wallet$/);
|
||||
expect(screen.getByRole('button', { name: /Google Wallet/ })).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button'));
|
||||
await waitFor(() => expect(wallet.addGoogle).toHaveBeenCalledWith(42, 7, expect.any(String)));
|
||||
expect(wallet.add).not.toHaveBeenCalled();
|
||||
|
||||
@@ -57,10 +57,11 @@ export default function MWalletButton({ tripId, reservationId, onError, classNam
|
||||
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
|
||||
>
|
||||
{busy ? <Loader2 size={13} className="animate-spin" /> : <Wallet size={13} strokeWidth={2} />}
|
||||
{t(wallet === 'google' ? 'reservations.wallet.addGoogle' : 'reservations.wallet.add')}
|
||||
{t('reservations.wallet.short')}
|
||||
</button>
|
||||
);
|
||||
return className ? <div className={className}>{button}</div> : button;
|
||||
|
||||
@@ -180,14 +180,8 @@ function RoadtripStagePage({ planner, shell, dayId: pageDayId, alts, chrome }: O
|
||||
// A chip that may not be opened is not a button in the first place (`bookingOpens`),
|
||||
// so nothing is turned away silently here.
|
||||
const canEditBookings = planner.can('reservation_edit', planner.trip)
|
||||
const openBooking = (res: Reservation) => {
|
||||
if (planner.TRANSPORT_TYPES.has(res.type)) {
|
||||
shell.openSheet('transport', { reservationId: res.id })
|
||||
return
|
||||
}
|
||||
planner.setEditingReservation(res)
|
||||
planner.setShowReservationModal(true)
|
||||
}
|
||||
// Every booking opens its detail sheet, as on the desktop; its pencil edits it there.
|
||||
const openBooking = (res: Reservation) => shell.openSheet('transport', { reservationId: res.id })
|
||||
// A booked night at the edge of the stage is no stop, and has no stop sheet: it opens the
|
||||
// booking behind the night, else the stay for somebody who may edit days, else the
|
||||
// hotel's place, the way a stay chip in the day timeline does (#2210).
|
||||
|
||||
@@ -111,19 +111,11 @@ export default function MDaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
}
|
||||
}
|
||||
|
||||
// A booking opens its detail sheet, as on the desktop; its pencil edits it there.
|
||||
const openReservation = (r: Reservation) => {
|
||||
const isTransport = planner.TRANSPORT_TYPES.has(r.type)
|
||||
if (isTransport && canEditDays) {
|
||||
planner.setEditingTransport(r)
|
||||
planner.setTransportModalDayId(r.day_id ?? null)
|
||||
planner.setShowTransportModal(true)
|
||||
} else if (!isTransport && canEditReservations) {
|
||||
planner.setEditingReservation(r)
|
||||
planner.setShowReservationModal(true)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
shell.closeSheet()
|
||||
if (isTransport ? !canEditDays : !canEditReservations) return
|
||||
shell.openSheet('transport', { reservationId: r.id })
|
||||
}
|
||||
|
||||
const planTransit = () => {
|
||||
|
||||
@@ -112,18 +112,11 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
)
|
||||
const openRes = (res: Reservation) => {
|
||||
if (!canOpenRes(res)) return
|
||||
if (planner.TRANSPORT_TYPES.has(res.type)) {
|
||||
planner.setEditingTransport(res)
|
||||
planner.setTransportModalDayId(res.day_id ?? null)
|
||||
planner.setTransportModalAutomated(false)
|
||||
planner.setShowTransportModal(true)
|
||||
} else {
|
||||
planner.setEditingReservation(res)
|
||||
planner.setShowReservationModal(true)
|
||||
}
|
||||
// This sheet hangs off the place selection, not the sheet stack, so its own
|
||||
// close() is what dismisses it — otherwise the editor opens on top of it.
|
||||
// close() is what dismisses it; the booking's detail sheet then opens alone,
|
||||
// with its pencil for editing, as on the desktop.
|
||||
close()
|
||||
shell.openSheet('transport', { reservationId: res.id })
|
||||
}
|
||||
|
||||
const participants = assignmentInDay?.participants || []
|
||||
@@ -413,7 +406,6 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
type="button"
|
||||
onClick={() => openRes(res)}
|
||||
disabled={!canOpenRes(res)}
|
||||
aria-label={canOpenRes(res) ? t('inspector.editRes') : undefined}
|
||||
className={`flex w-full items-center gap-2 rounded-[14px] px-3 py-[10px] text-start ${INNER_CLS}`}
|
||||
>
|
||||
<span
|
||||
|
||||
@@ -103,6 +103,7 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
|
||||
})
|
||||
|
||||
const canEditDays = planner.can('day_edit', planner.trip)
|
||||
const canEditBookings = planner.can('reservation_edit', planner.trip)
|
||||
const timeFormat = useSettingsStore(s => s.settings.time_format) || '24h'
|
||||
const blurCodes = useSettingsStore(s => s.settings.blur_booking_codes)
|
||||
const [codeRevealed, setCodeRevealed] = useState(false)
|
||||
@@ -118,6 +119,9 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
|
||||
}
|
||||
|
||||
const meta = parseMetadata(res)
|
||||
// A transport is part of the day plan, a stay, a table or a ticket a booking:
|
||||
// each is edited under its own permission, as in the tab it belongs to.
|
||||
const canEdit = isTransportReservationType(res.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')
|
||||
@@ -362,7 +366,7 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
|
||||
<span dir="auto" className="truncate">{f.original_name}</span>
|
||||
</button>
|
||||
))}
|
||||
{canEditDays && (
|
||||
{canEdit && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={editTransport}
|
||||
@@ -372,7 +376,7 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
|
||||
{t('common.edit')}
|
||||
</button>
|
||||
)}
|
||||
{canEditDays && (
|
||||
{canEdit && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={deleteTransport}
|
||||
|
||||
@@ -69,6 +69,7 @@ export default function MBookingsTab({ planner, shell }: MTabScreenProps) {
|
||||
planner={planner}
|
||||
canEdit={canEdit}
|
||||
compact={shell.bookingsCompact}
|
||||
onView={() => shell.openSheet('transport', { reservationId: res.id })}
|
||||
/>
|
||||
))}
|
||||
</CardGrid>
|
||||
@@ -79,10 +80,12 @@ export default function MBookingsTab({ planner, shell }: MTabScreenProps) {
|
||||
)
|
||||
}
|
||||
|
||||
function BookingCard({ res, planner, canEdit, compact }: {
|
||||
function BookingCard({ res, planner, canEdit, compact, onView }: {
|
||||
res: Reservation
|
||||
planner: MTabScreenProps['planner']
|
||||
canEdit: boolean
|
||||
/** A tap on the card: the booking's detail sheet, as a transport opens, and as on the desktop. */
|
||||
onView: () => void
|
||||
compact: boolean
|
||||
}) {
|
||||
const { t, days } = planner
|
||||
@@ -139,7 +142,7 @@ function BookingCard({ res, planner, canEdit, compact }: {
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-[7px] border-b border-[color:var(--m-rowbr)] px-3 py-[10px]" style={{ background: tint }}>
|
||||
<StatusDot color={dotColor} />
|
||||
<CardTitleButton res={res} TypeIcon={TypeIcon} typeColor={typeColor} onOpen={openEdit} t={t} />
|
||||
<CardTitleButton res={res} TypeIcon={TypeIcon} typeColor={typeColor} onOpen={onView} t={t} />
|
||||
{canEdit && <CardActions onEdit={openEdit} onDelete={card.askDelete} t={t} />}
|
||||
</div>
|
||||
|
||||
@@ -154,11 +157,11 @@ function BookingCard({ res, planner, canEdit, compact }: {
|
||||
timeValue={timeValue}
|
||||
code={res.confirmation_number}
|
||||
card={card}
|
||||
onOpen={openEdit}
|
||||
onOpen={onView}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<button type="button" onClick={openEdit} className="block w-full text-start">
|
||||
<button type="button" onClick={onView} className="block w-full text-start">
|
||||
{metaCells.length > 0 && (
|
||||
<div className="mt-2 flex gap-2">
|
||||
{metaCells.slice(0, 3).map((c, i) => (
|
||||
|
||||
Reference in New Issue
Block a user