mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 00:45:41 +00:00
auto allocation and batch managemnt, tracking the train
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
||||
import type { FleetResourceSlug } from "@/pages/fleet/config/resources";
|
||||
import type { FleetListFilters, FleetResourceSlug } from "@/services/fleet/fleet.service";
|
||||
import { fleetService } from "@/services/fleet/fleet.service";
|
||||
|
||||
export function useFleetList(slug: FleetResourceSlug) {
|
||||
export function useFleetList(slug: FleetResourceSlug, filters?: FleetListFilters) {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.FLEET.list(slug),
|
||||
queryFn: () => fleetService.list(slug),
|
||||
queryKey: [...QUERY_KEYS.FLEET.list(slug), filters ?? {}],
|
||||
queryFn: () => fleetService.list(slug, filters),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,27 @@ export const useBatchBoard = () =>
|
||||
refetchInterval: 30_000,
|
||||
});
|
||||
|
||||
export const useBatchBoardDetail = (scheduleId: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(scheduleId ?? ""),
|
||||
queryFn: () => trainSchedulingService.getBatchBoardDetail(scheduleId!),
|
||||
enabled: Boolean(scheduleId),
|
||||
refetchInterval: 30_000,
|
||||
});
|
||||
|
||||
export const useRunAllocation = (scheduleId: string) => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: () => trainSchedulingService.runAllocation(scheduleId),
|
||||
onSuccess: () => {
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(scheduleId),
|
||||
});
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoard() });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useScheduleDetail = (id: string | undefined, freightType?: FreightType) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.scheduleById(id ?? ""),
|
||||
@@ -43,10 +64,11 @@ export const useEligibleBookings = (
|
||||
enabled,
|
||||
});
|
||||
|
||||
export const useAvailableLocomotives = () =>
|
||||
export const useAvailableLocomotives = (routeId?: string) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.locomotives(),
|
||||
queryFn: () => trainSchedulingService.getAvailableLocomotives(),
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.locomotives(routeId),
|
||||
queryFn: () => trainSchedulingService.getAvailableLocomotives(routeId),
|
||||
enabled: routeId ? Boolean(routeId) : true,
|
||||
});
|
||||
|
||||
export const useBatchActions = (scheduleId?: string) => {
|
||||
@@ -54,10 +76,14 @@ export const useBatchActions = (scheduleId?: string) => {
|
||||
const invalidate = () => {
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.TRAIN_SCHEDULING.ROOT });
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.BOOKINGS.ROOT });
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoard() });
|
||||
if (scheduleId) {
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.scheduleById(scheduleId),
|
||||
});
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(scheduleId),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { wagonService } from '@/services/wagon.service';
|
||||
|
||||
export type WagonListFilters = import('@/services/wagon.service').WagonListFilters;
|
||||
|
||||
export const wagonKeys = {
|
||||
all: ['wagons'] as const,
|
||||
list: (filters?: WagonListFilters) => [...wagonKeys.all, 'list', filters ?? {}] as const,
|
||||
byTrain: (trainId: string) => [...wagonKeys.all, 'train', trainId] as const,
|
||||
details: () => [...wagonKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...wagonKeys.details(), id] as const,
|
||||
};
|
||||
|
||||
export function useWagons() {
|
||||
return useQuery({ queryKey: wagonKeys.all, queryFn: () => wagonService.getAll().then(res => res.data) });
|
||||
export function useWagons(filters?: WagonListFilters) {
|
||||
return useQuery({
|
||||
queryKey: wagonKeys.list(filters),
|
||||
queryFn: () => wagonService.getAll(filters ?? {}).then((res) => res.data),
|
||||
});
|
||||
}
|
||||
|
||||
export const useGetWagons = useWagons;
|
||||
|
||||
Reference in New Issue
Block a user