* Revert "fix: revert bookings redesign (#25172)"
This reverts commit 1f102bf3b4.
* add bookings-v3 feature flag
* put things behind a feature flag
* remove no longer needed test
* revert e2e tests
* put back description
* revert AvatarGroup
* apply feedback
* remove "view" booking action
* remove Alert (When the bookings query errors, this branch now renders only the alert and skips the data-table filter/segment controls. Those controls moved into BookingsList, so in error states users can no longer clear or tweak filters to recover from the failure, effectively trapping them behind the alert.)
* address feedback
* revert useMediaQuery
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { useMemo, useCallback } from "react";
|
|
|
|
import type { BookingOutput } from "../types";
|
|
|
|
export function useBookingCursor({
|
|
bookings,
|
|
selectedBookingId,
|
|
setSelectedBookingId,
|
|
}: {
|
|
bookings: BookingOutput[];
|
|
selectedBookingId: number | null;
|
|
setSelectedBookingId: (bookingId: number | null) => void;
|
|
}) {
|
|
const currentIndex = useMemo(
|
|
() => bookings.findIndex((booking) => selectedBookingId && booking.id === selectedBookingId),
|
|
[bookings, selectedBookingId]
|
|
);
|
|
|
|
const onPrevious = useCallback(() => {
|
|
if (currentIndex >= 1) {
|
|
setSelectedBookingId(bookings[currentIndex - 1].id);
|
|
}
|
|
}, [bookings, currentIndex, setSelectedBookingId]);
|
|
|
|
const onNext = useCallback(() => {
|
|
if (currentIndex >= 0 && currentIndex < bookings.length - 1) {
|
|
setSelectedBookingId(bookings[currentIndex + 1].id);
|
|
}
|
|
}, [bookings, currentIndex, setSelectedBookingId]);
|
|
|
|
return {
|
|
onPrevious,
|
|
onNext,
|
|
hasPrevious: currentIndex > 0,
|
|
hasNext: currentIndex < bookings.length - 1 && currentIndex >= 0,
|
|
};
|
|
}
|