mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
schedule logic
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
CreateTrainSchedulePayload,
|
||||
FreightType,
|
||||
PinWagonsPayload,
|
||||
RecordCheckpointPayload,
|
||||
TrainScheduleFilters,
|
||||
TrainSchedulePreviewPayload,
|
||||
} from "@/types/trainScheduling";
|
||||
@@ -41,6 +42,13 @@ export const useAvailableLocomotives = () =>
|
||||
queryFn: () => trainSchedulingService.getAvailableLocomotives(),
|
||||
});
|
||||
|
||||
export const useTrainTrack = (id: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.track(id ?? ""),
|
||||
queryFn: () => trainSchedulingService.getTrack(id!),
|
||||
enabled: Boolean(id),
|
||||
});
|
||||
|
||||
export const useScheduleMutations = (scheduleId?: string) => {
|
||||
const qc = useQueryClient();
|
||||
|
||||
@@ -52,6 +60,9 @@ export const useScheduleMutations = (scheduleId?: string) => {
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.scheduleById(scheduleId),
|
||||
});
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.track(scheduleId),
|
||||
});
|
||||
}
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.BOOKINGS.ROOT });
|
||||
};
|
||||
@@ -118,5 +129,28 @@ export const useScheduleMutations = (scheduleId?: string) => {
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { create, preview, assign, unassign, pin, finalize, dispatch, cancel, invalidate };
|
||||
const recordCheckpoint = useMutation({
|
||||
mutationFn: ({ id, payload }: { id: string; payload: RecordCheckpointPayload }) =>
|
||||
trainSchedulingService.recordCheckpoint(id, payload),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const arrive = useMutation({
|
||||
mutationFn: (id: string) => trainSchedulingService.arriveSchedule(id),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return {
|
||||
create,
|
||||
preview,
|
||||
assign,
|
||||
unassign,
|
||||
pin,
|
||||
finalize,
|
||||
dispatch,
|
||||
cancel,
|
||||
recordCheckpoint,
|
||||
arrive,
|
||||
invalidate,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user