mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
feat(bookings): download button on booking and transport attachments (#2585)
Each attached file row now has a download icon next to its name, on the desktop booking cards and detail dialog and on the phone's bookings and transports cards. On the phone the file rows move out of the card body button so open and download are two real sibling buttons.
This commit is contained in:
@@ -185,9 +185,9 @@ function BookingCard({ res, planner, canEdit, compact, onView }: {
|
||||
)}
|
||||
|
||||
<CardNotes notes={res.notes} />
|
||||
|
||||
<CardFiles files={files} card={card} t={t} />
|
||||
</button>
|
||||
|
||||
<CardFiles files={files} card={card} t={t} />
|
||||
</div>
|
||||
)}
|
||||
{!compact && <ReservationPluginSlots tripId={planner.tripId} reservationId={res.id} />}
|
||||
|
||||
@@ -29,7 +29,8 @@ function cardState(overrides: Partial<ReturnType<typeof useReservationCard>> = {
|
||||
askDelete: vi.fn(),
|
||||
cancelDelete: vi.fn(),
|
||||
confirmDelete: vi.fn(),
|
||||
fileChip: () => ({ onClick: vi.fn(), onKeyDown: vi.fn() }),
|
||||
openFile: vi.fn(),
|
||||
downloadFile: vi.fn(),
|
||||
...overrides,
|
||||
} as unknown as ReturnType<typeof useReservationCard>;
|
||||
}
|
||||
@@ -130,18 +131,30 @@ describe('MReservationCardParts', () => {
|
||||
expect(toggleCode).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('FE-COMP-MRESCARD-006: files render as button-role chips, and no files render nothing', () => {
|
||||
it('FE-COMP-MRESCARD-006: each file row opens the file by its name and downloads it by the icon (#2585)', () => {
|
||||
const { container, rerender } = render(<CardFiles files={[]} card={cardState()} t={t} />);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
|
||||
const files = [{ id: 5, original_name: 'ticket.pdf', url: '/uploads/f/5' }] as Parameters<
|
||||
typeof CardFiles
|
||||
>[0]['files'];
|
||||
rerender(<CardFiles files={files} card={cardState()} t={t} />);
|
||||
const card = cardState();
|
||||
rerender(<CardFiles files={files} card={card} t={t} />);
|
||||
expect(screen.getByText('files.title')).toBeInTheDocument();
|
||||
const chip = screen.getByRole('button', { name: 'ticket.pdf' });
|
||||
expect(chip.tagName).toBe('SPAN');
|
||||
expect(chip).toHaveAttribute('tabindex', '0');
|
||||
|
||||
const open = screen.getByRole('button', { name: 'ticket.pdf' });
|
||||
const download = screen.getByRole('button', { name: 'files.download: ticket.pdf' });
|
||||
// Two sibling buttons, never one inside the other.
|
||||
expect(open.tagName).toBe('BUTTON');
|
||||
expect(open.contains(download)).toBe(false);
|
||||
expect(download.closest('button')).toBe(download);
|
||||
|
||||
fireEvent.click(open);
|
||||
expect(card.openFile).toHaveBeenCalledWith(files[0]);
|
||||
expect(card.downloadFile).not.toHaveBeenCalled();
|
||||
fireEvent.click(download);
|
||||
expect(card.downloadFile).toHaveBeenCalledWith(files[0]);
|
||||
expect(card.openFile).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('FE-COMP-MRESCARD-007: the delete sheet names the reservation and confirms through the card', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FileText, type LucideIcon, Pencil, Trash2 } from 'lucide-react';
|
||||
import { Download, FileText, type LucideIcon, Pencil, Trash2 } from 'lucide-react';
|
||||
|
||||
import type { useReservationCard } from '../../../../components/Planner/bookings/useReservationCard';
|
||||
import type { useTranslation } from '../../../../i18n';
|
||||
@@ -163,7 +163,11 @@ export function CardNotes({ notes }: { notes: string | null | undefined }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Attached files, listed inside the card body button. */
|
||||
/**
|
||||
* Attached files, under the card body button rather than inside it, so each row
|
||||
* 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 }) {
|
||||
if (files.length === 0) return null;
|
||||
return (
|
||||
@@ -172,21 +176,30 @@ export function CardFiles({ files, card, t }: { files: ReturnType<typeof filesFo
|
||||
{t('files.title')}
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
{/* A span with a button role, not a <button>: the whole card body
|
||||
is already one, and buttons cannot nest. */}
|
||||
{files.map((f) => (
|
||||
<span
|
||||
<div
|
||||
key={f.id}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
{...card.fileChip(f)}
|
||||
className="flex items-center gap-[6px] rounded-[10px] border border-[color:var(--m-rowbr)] bg-m-card px-[10px] py-[7px]"
|
||||
className="flex items-stretch overflow-hidden rounded-[10px] border border-[color:var(--m-rowbr)] bg-m-card"
|
||||
>
|
||||
<FileText size={12} strokeWidth={2} className="flex-none text-m-muted" />
|
||||
<span dir="auto" className="truncate font-geist text-[0.65625rem] font-semibold text-m-muted">
|
||||
{f.original_name}
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => card.openFile(f)}
|
||||
className="flex min-w-0 flex-1 items-center gap-[6px] py-[7px] pe-1 ps-[10px] text-start"
|
||||
>
|
||||
<FileText size={12} strokeWidth={2} className="flex-none text-m-muted" />
|
||||
<span dir="auto" className="truncate font-geist text-[0.65625rem] font-semibold text-m-muted">
|
||||
{f.original_name}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => card.downloadFile(f)}
|
||||
aria-label={`${t('files.download')}: ${f.original_name}`}
|
||||
className="grid w-9 flex-none place-items-center text-m-muted"
|
||||
>
|
||||
<Download size={13} strokeWidth={2} />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -194,9 +194,9 @@ function TransportCard({ res, planner, shell, canEdit, compact }: {
|
||||
<TravelerAvatars travelers={res.travelers || []} label={t('reservations.travelers.label')} />
|
||||
|
||||
<CardNotes notes={res.notes} />
|
||||
|
||||
<CardFiles files={files} card={card} t={t} />
|
||||
</button>
|
||||
|
||||
<CardFiles files={files} card={card} t={t} />
|
||||
</div>
|
||||
)}
|
||||
{!compact && <ReservationPluginSlots tripId={planner.tripId} reservationId={res.id} />}
|
||||
|
||||
Reference in New Issue
Block a user