mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 23:28:11 +00:00
automate the schedule
This commit is contained in:
@@ -42,6 +42,63 @@ export const useAvailableLocomotives = () =>
|
||||
queryFn: () => trainSchedulingService.getAvailableLocomotives(),
|
||||
});
|
||||
|
||||
export const useBatchActions = (scheduleId?: string) => {
|
||||
const qc = useQueryClient();
|
||||
const invalidate = () => {
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.TRAIN_SCHEDULING.ROOT });
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.BOOKINGS.ROOT });
|
||||
if (scheduleId) {
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.scheduleById(scheduleId),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const runBatch = useMutation({
|
||||
mutationFn: (id: string) => trainSchedulingService.runBatch(id),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
const setWindow = useMutation({
|
||||
mutationFn: ({ id, status }: { id: string; status: "OPEN" | "CLOSED" }) =>
|
||||
trainSchedulingService.setBookingWindow(id, status),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
const markPaid = useMutation({
|
||||
mutationFn: (bookingId: string) => trainSchedulingService.markBookingPaid(bookingId),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
const expire = useMutation({
|
||||
mutationFn: (bookingId: string) => trainSchedulingService.expireBooking(bookingId),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
const moveSchedule = useMutation({
|
||||
mutationFn: ({ bookingId, trainScheduleId }: { bookingId: string; trainScheduleId: string }) =>
|
||||
trainSchedulingService.moveBookingSchedule(bookingId, trainScheduleId),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { runBatch, setWindow, markPaid, expire, moveSchedule, invalidate };
|
||||
};
|
||||
|
||||
export const useBookableSchedules = (
|
||||
originYardId?: string | null,
|
||||
destinationYardId?: string | null,
|
||||
) =>
|
||||
useQuery({
|
||||
queryKey: [
|
||||
...QUERY_KEYS.TRAIN_SCHEDULING.ROOT,
|
||||
"bookable",
|
||||
originYardId ?? "",
|
||||
destinationYardId ?? "",
|
||||
],
|
||||
queryFn: () =>
|
||||
trainSchedulingService.getBookableSchedules(
|
||||
originYardId ?? undefined,
|
||||
destinationYardId ?? undefined,
|
||||
),
|
||||
enabled: Boolean(originYardId && destinationYardId),
|
||||
});
|
||||
|
||||
export const useTrainTrack = (id: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.track(id ?? ""),
|
||||
|
||||
Reference in New Issue
Block a user