mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
1b51181930
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.
39 lines
1.1 KiB
TypeScript
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,
|
|
};
|
|
}
|