Files
TREK/client/src/components/Planner/bookings/useReservationDelete.ts
T
Maurice 1b51181930 refactor(planner): share the bookings and transports list filters between desktop and phone
The bookings model moves from the phone tabs into components/Planner/bookings, so
both shells read the same sections, traveller predicate and type colours. The
phone bookings and transports tabs had the same traveller filter and folded
sections twice; that state now lives once in useReservationListFilter, which only
those two tabs use. The desktop panel keeps its own filters in useBookingsView
because it remembers them for the session.

The status switch and the delete on a booking card stay per shell. The desktop
hook renders its ConfirmDialog and awaits the delete, the phone asks in an
MConfirmSheet and lets the delete run on its own; sharing them would change
when the question closes.
2026-10-09 15:19:40 +02:00

39 lines
1.1 KiB
TypeScript

import { useState } from 'react';
import type { Reservation } from '../../../types';
/**
* Deleting a booking after a question, for the desktop bookings panel and the
* cards of the phone's bookings and transports tabs. `requestDelete` asks,
* `cancelDelete` drops the question, `confirmDelete` answers it: the question
* closes first, then `beforeDelete` runs (the desktop closes a detail showing
* that booking) and the delete goes out. A failed delete calls `onError`, so
* each view keeps its own toast.
*/
export function useReservationDelete(
onDelete: (id: number) => unknown,
onError: () => void,
beforeDelete?: (r: Reservation) => void
) {
const [pendingDelete, setPendingDelete] = useState<Reservation | null>(null);
const confirmDelete = async () => {
const r = pendingDelete;
setPendingDelete(null);
if (!r) return;
beforeDelete?.(r);
try {
await onDelete(r.id);
} catch {
onError();
}
};
return {
pendingDelete,
requestDelete: setPendingDelete,
cancelDelete: () => setPendingDelete(null),
confirmDelete,
};
}