mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 12:18:11 +00:00
feat(bookings): Integrate booking list and detail pages with backend API
This commit is contained in:
48
apps/edr-freight-web/backoffice/src/hooks/useBookings.ts
Normal file
48
apps/edr-freight-web/backoffice/src/hooks/useBookings.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { api } from "@/services/api";
|
||||
import type { BookingListFilter } from "@/services/bookings.service";
|
||||
|
||||
export const useBookingList = (filter?: BookingListFilter) => {
|
||||
const input = { filter };
|
||||
return {
|
||||
queryKey: api.bookings.list.queryKey(input),
|
||||
queryFn: () => api.bookings.list.call(input),
|
||||
};
|
||||
};
|
||||
|
||||
export const useBooking = (id: string) => ({
|
||||
queryKey: api.bookings.getById.queryKey({ id }),
|
||||
queryFn: () => api.bookings.getById.call({ id }),
|
||||
enabled: Boolean(id),
|
||||
});
|
||||
|
||||
export const useUpdateBookingStatus = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
action,
|
||||
reason,
|
||||
}: {
|
||||
id: string;
|
||||
action: string;
|
||||
reason?: string;
|
||||
}) => api.bookings.updateStatus.call({ id, action, reason }),
|
||||
onSuccess: (_data, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: api.bookings.list.queryKey() });
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.bookings.getById.queryKey({ id }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteBooking = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.bookings.remove.call({ id }),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({ queryKey: api.bookings.list.queryKey() }),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user