mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
merge conflict fix
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
||||
import type { FleetListFilters, FleetResourceSlug } from "@/services/fleet/fleet.service";
|
||||
import { fleetService } from "@/services/fleet/fleet.service";
|
||||
|
||||
export function useFleetList(slug: FleetResourceSlug, filters?: FleetListFilters) {
|
||||
return useQuery({
|
||||
queryKey: [...QUERY_KEYS.FLEET.list(slug), filters ?? {}],
|
||||
queryFn: () => fleetService.list(slug, filters),
|
||||
});
|
||||
}
|
||||
|
||||
export function useFleetMutations(slug: FleetResourceSlug) {
|
||||
const qc = useQueryClient();
|
||||
const invalidate = () => qc.invalidateQueries({ queryKey: QUERY_KEYS.FLEET.list(slug) });
|
||||
|
||||
const create = useMutation({
|
||||
mutationFn: (data: Record<string, unknown>) => fleetService.create(slug, data),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const update = useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: Record<string, unknown> }) =>
|
||||
fleetService.update(slug, id, data),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const remove = useMutation({
|
||||
mutationFn: (id: string) => fleetService.remove(slug, id),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { create, update, remove };
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
||||
import { trainSchedulingService } from "@/services/trainScheduling.service";
|
||||
import type {
|
||||
AssignBookingsPayload,
|
||||
CreateTrainSchedulePayload,
|
||||
FreightType,
|
||||
PinWagonsPayload,
|
||||
RecordCheckpointPayload,
|
||||
TrainScheduleFilters,
|
||||
TrainSchedulePreviewPayload,
|
||||
} from "@/types/trainScheduling";
|
||||
|
||||
export const useScheduleList = (freightType?: FreightType) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.schedules(),
|
||||
queryFn: () => trainSchedulingService.listSchedules(freightType),
|
||||
});
|
||||
|
||||
export const useBatchBoard = () =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoard(),
|
||||
queryFn: () => trainSchedulingService.getBatchBoard(),
|
||||
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 ?? ""),
|
||||
queryFn: () => trainSchedulingService.getScheduleById(id!, freightType),
|
||||
enabled: Boolean(id),
|
||||
});
|
||||
|
||||
export const useEligibleBookings = (
|
||||
filters?: TrainScheduleFilters,
|
||||
enabled = true,
|
||||
freightType?: FreightType,
|
||||
) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.eligible(freightType, filters),
|
||||
queryFn: () => trainSchedulingService.getEligibleBookings(filters, freightType),
|
||||
enabled,
|
||||
});
|
||||
|
||||
export const useAvailableLocomotives = (routeId?: string) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.locomotives(routeId),
|
||||
queryFn: () => trainSchedulingService.getAvailableLocomotives(routeId),
|
||||
enabled: routeId ? Boolean(routeId) : true,
|
||||
});
|
||||
|
||||
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 });
|
||||
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),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
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),
|
||||
});
|
||||
|
||||
/**
|
||||
* Day-level pool: which days have an OPEN departure on the route. Staff pick a
|
||||
* day (not a train) when creating a booking; the engine assigns the train.
|
||||
*/
|
||||
export const useAvailableDays = (
|
||||
originYardId?: string | null,
|
||||
destinationYardId?: string | null,
|
||||
) =>
|
||||
useQuery({
|
||||
queryKey: [
|
||||
...QUERY_KEYS.TRAIN_SCHEDULING.ROOT,
|
||||
"available-days",
|
||||
originYardId ?? "",
|
||||
destinationYardId ?? "",
|
||||
],
|
||||
queryFn: () =>
|
||||
trainSchedulingService.getAvailableDays(
|
||||
originYardId ?? undefined,
|
||||
destinationYardId ?? undefined,
|
||||
),
|
||||
enabled: Boolean(originYardId && destinationYardId),
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
const invalidate = () => {
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.TRAIN_SCHEDULING.ROOT });
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.TRAIN_SCHEDULING.schedules() });
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.TRAIN_SCHEDULING.locomotives() });
|
||||
if (scheduleId) {
|
||||
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.TRAIN_SCHEDULING.unassignedBookings(scheduleId),
|
||||
});
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.compositionRemovals(scheduleId),
|
||||
});
|
||||
}
|
||||
void qc.invalidateQueries({ queryKey: QUERY_KEYS.BOOKINGS.ROOT });
|
||||
};
|
||||
|
||||
const create = useMutation({
|
||||
mutationFn: ({
|
||||
freightType,
|
||||
payload,
|
||||
}: {
|
||||
freightType?: FreightType;
|
||||
payload: CreateTrainSchedulePayload;
|
||||
}) => trainSchedulingService.createSchedule(payload, freightType),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const preview = useMutation({
|
||||
mutationFn: ({
|
||||
freightType,
|
||||
payload,
|
||||
}: {
|
||||
freightType?: FreightType;
|
||||
payload: TrainSchedulePreviewPayload;
|
||||
}) => trainSchedulingService.preview(payload, freightType),
|
||||
});
|
||||
|
||||
const assign = useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
freightType,
|
||||
payload,
|
||||
}: {
|
||||
id: string;
|
||||
freightType?: FreightType;
|
||||
payload: AssignBookingsPayload;
|
||||
}) => trainSchedulingService.assignBookings(id, payload, freightType),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const assignUnassigned = useMutation({
|
||||
mutationFn: ({ id, bookingId }: { id: string; bookingId: string }) =>
|
||||
trainSchedulingService.assignUnassignedBooking(id, bookingId),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const unassign = useMutation({
|
||||
mutationFn: ({ id, bookingId }: { id: string; bookingId: string }) =>
|
||||
trainSchedulingService.unassignBooking(id, bookingId),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const pin = useMutation({
|
||||
mutationFn: ({ id, payload }: { id: string; payload: PinWagonsPayload }) =>
|
||||
trainSchedulingService.pinWagons(id, payload),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const finalize = useMutation({
|
||||
mutationFn: (id: string) => trainSchedulingService.finalizeSchedule(id),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const dispatch = useMutation({
|
||||
mutationFn: (id: string) => trainSchedulingService.dispatchSchedule(id),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const cancel = useMutation({
|
||||
mutationFn: ({ id, freightType }: { id: string; freightType?: FreightType }) =>
|
||||
trainSchedulingService.cancelSchedule(id, freightType ?? "CONTAINER"),
|
||||
onSuccess: 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,
|
||||
assignUnassigned,
|
||||
unassign,
|
||||
pin,
|
||||
finalize,
|
||||
dispatch,
|
||||
cancel,
|
||||
recordCheckpoint,
|
||||
arrive,
|
||||
invalidate,
|
||||
};
|
||||
};
|
||||
|
||||
export const useUnassignedBookings = (scheduleId: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.unassignedBookings(scheduleId ?? ""),
|
||||
queryFn: () => trainSchedulingService.getUnassignedBookings(scheduleId!),
|
||||
enabled: Boolean(scheduleId),
|
||||
});
|
||||
|
||||
export const useCompositionRemovals = (scheduleId: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.compositionRemovals(scheduleId ?? ""),
|
||||
queryFn: () => trainSchedulingService.getCompositionRemovals(scheduleId!),
|
||||
enabled: Boolean(scheduleId),
|
||||
});
|
||||
|
||||
export const useRemoveWagonSlot = (scheduleId: string) => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (wagonId: string) =>
|
||||
trainSchedulingService.removeWagonSlot(scheduleId, wagonId),
|
||||
onSuccess: () => {
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.scheduleById(scheduleId),
|
||||
});
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(scheduleId),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateContainerItem = (scheduleId: string) => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ itemId, containerNumber }: { itemId: string; containerNumber: string | null }) =>
|
||||
trainSchedulingService.updateContainerItem(scheduleId, itemId, { containerNumber }),
|
||||
onSuccess: () => {
|
||||
void qc.invalidateQueries({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.scheduleById(scheduleId),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { cargoTypesService } from '@/services/cargo-types.service';
|
||||
|
||||
export const CARGO_TYPES_QUERY_KEY = ['cargo-types'];
|
||||
|
||||
export function useCargoTypes() {
|
||||
return useQuery({
|
||||
queryKey: CARGO_TYPES_QUERY_KEY,
|
||||
queryFn: () => cargoTypesService.getCargoTypes(),
|
||||
staleTime: Infinity,
|
||||
});
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { containerTypesService } from '@/services/container-types.service';
|
||||
|
||||
export const CONTAINER_TYPES_QUERY_KEY = ['container-types'];
|
||||
|
||||
export function useContainerTypes() {
|
||||
return useQuery({
|
||||
queryKey: CONTAINER_TYPES_QUERY_KEY,
|
||||
queryFn: () => containerTypesService.getContainerTypes(),
|
||||
staleTime: Infinity,
|
||||
});
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { wagonTypesService } from '@/services/wagon-types.service';
|
||||
|
||||
export const WAGON_TYPES_QUERY_KEY = ['wagon-types'];
|
||||
|
||||
export function useWagonTypes() {
|
||||
return useQuery({
|
||||
queryKey: WAGON_TYPES_QUERY_KEY,
|
||||
queryFn: () => wagonTypesService.getWagonTypes(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateWagonType() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: wagonTypesService.create,
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: WAGON_TYPES_QUERY_KEY }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateWagonType() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: Record<string, unknown> }) =>
|
||||
wagonTypesService.update(id, data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: WAGON_TYPES_QUERY_KEY }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteWagonType() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: wagonTypesService.delete,
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: WAGON_TYPES_QUERY_KEY }),
|
||||
});
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { cargoService, type DeliverCargoPayload } from '@/services/cargoService';
|
||||
|
||||
export const cargoKeys = {
|
||||
all: ['cargoes'] as const,
|
||||
byContainer: (containerId: string) => [...cargoKeys.all, 'container', containerId] as const,
|
||||
details: () => [...cargoKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...cargoKeys.details(), id] as const,
|
||||
};
|
||||
|
||||
export function useCargoes() {
|
||||
return useQuery({ queryKey: cargoKeys.all, queryFn: () => cargoService.getAll().then(res => res.data) });
|
||||
}
|
||||
|
||||
export const useGetCargoes = useCargoes;
|
||||
|
||||
export function useCargoesByContainer(containerId: string) {
|
||||
return useQuery({ queryKey: cargoKeys.byContainer(containerId), queryFn: () => cargoService.getByContainer(containerId).then(res => res.data), enabled: !!containerId });
|
||||
}
|
||||
|
||||
export function useCargo(id: string) {
|
||||
return useQuery({ queryKey: cargoKeys.detail(id), queryFn: () => cargoService.getById(id).then(res => res.data), enabled: !!id });
|
||||
}
|
||||
|
||||
export const useGetCargo = useCargo;
|
||||
|
||||
export function useCreateCargo() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: cargoService.create, onSuccess: () => qc.invalidateQueries({ queryKey: cargoKeys.all }) });
|
||||
}
|
||||
|
||||
export function useUpdateCargo() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: ({ id, data }: any) => cargoService.update(id, data), onSuccess: (_, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: cargoKeys.all });
|
||||
qc.invalidateQueries({ queryKey: cargoKeys.detail(id) });
|
||||
} });
|
||||
}
|
||||
|
||||
export function useDeleteCargo() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: cargoService.delete, onSuccess: () => qc.invalidateQueries({ queryKey: cargoKeys.all }) });
|
||||
}
|
||||
|
||||
export function useLoadCargo() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, quantity, weight, volume }: any) => cargoService.load(id, quantity, weight, volume),
|
||||
onSuccess: (_, { id }) => qc.invalidateQueries({ queryKey: cargoKeys.all })
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeliverCargo() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, payload }: { id: string; payload?: DeliverCargoPayload }) =>
|
||||
cargoService.deliver(id, payload),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: cargoKeys.all })
|
||||
});
|
||||
}
|
||||
|
||||
export function useUnloadCargo() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => cargoService.unload(id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: cargoKeys.all })
|
||||
});
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { containerService } from '@/services/containerService';
|
||||
|
||||
export const containerKeys = {
|
||||
all: ['containers'] as const,
|
||||
byWagon: (wagonId: string) => [...containerKeys.all, 'wagon', wagonId] as const,
|
||||
details: () => [...containerKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...containerKeys.details(), id] as const,
|
||||
};
|
||||
|
||||
export function useContainers() {
|
||||
return useQuery({ queryKey: containerKeys.all, queryFn: () => containerService.getAll().then(res => res.data) });
|
||||
}
|
||||
|
||||
export const useGetContainers = useContainers;
|
||||
|
||||
export function useContainersByWagon(wagonId: string) {
|
||||
return useQuery({ queryKey: containerKeys.byWagon(wagonId), queryFn: () => containerService.getByWagon(wagonId).then(res => res.data), enabled: !!wagonId });
|
||||
}
|
||||
|
||||
export function useContainer(id: string) {
|
||||
return useQuery({ queryKey: containerKeys.detail(id), queryFn: () => containerService.getById(id).then(res => res.data), enabled: !!id });
|
||||
}
|
||||
|
||||
export const useGetContainer = useContainer;
|
||||
|
||||
export function useCreateContainer() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: containerService.create, onSuccess: () => qc.invalidateQueries({ queryKey: containerKeys.all }) });
|
||||
}
|
||||
|
||||
export function useUpdateContainer() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: ({ id, data }: any) => containerService.update(id, data), onSuccess: (_, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: containerKeys.all });
|
||||
qc.invalidateQueries({ queryKey: containerKeys.detail(id) });
|
||||
} });
|
||||
}
|
||||
|
||||
export function useDeleteContainer() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: containerService.delete, onSuccess: () => qc.invalidateQueries({ queryKey: containerKeys.all }) });
|
||||
}
|
||||
|
||||
export function useAssignContainerToWagon() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ containerId, wagonId, position }: any) => containerService.assignToWagon(containerId, wagonId, position),
|
||||
onSuccess: (_, { wagonId }) => qc.invalidateQueries({ queryKey: containerKeys.byWagon(wagonId) })
|
||||
});
|
||||
}
|
||||
|
||||
export function useUnassignContainer() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: containerService.unassign,
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: containerKeys.all })
|
||||
});
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { api } from "@/services/api";
|
||||
import type {
|
||||
CreateDropdownOptionDto,
|
||||
CreateDropdownSettingDto,
|
||||
UpdateDropdownOptionDto,
|
||||
UpdateDropdownSettingDto,
|
||||
} from "@/types/dropdownSettings";
|
||||
|
||||
/* ----------------------------- Mutations ----------------------------- */
|
||||
|
||||
export const useCreateDropdownSetting = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (dto: CreateDropdownSettingDto) =>
|
||||
api.dropdownSettings.create.call(dto),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({ queryKey: api.dropdownSettings.list.queryKey() }),
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateDropdownSetting = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
dto,
|
||||
}: {
|
||||
id: string;
|
||||
dto: UpdateDropdownSettingDto;
|
||||
}) => api.dropdownSettings.update.call({ id, dto }),
|
||||
onSuccess: (_data, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: api.dropdownSettings.list.queryKey() });
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.dropdownSettings.getById.queryKey({ id }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteDropdownSetting = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.dropdownSettings.remove.call({ id }),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({ queryKey: api.dropdownSettings.list.queryKey() }),
|
||||
});
|
||||
};
|
||||
|
||||
export const useReplaceDropdownOptions = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
settingId,
|
||||
options,
|
||||
}: {
|
||||
settingId: string;
|
||||
options: CreateDropdownOptionDto[];
|
||||
}) => api.dropdownSettings.replaceOptions.call({ id: settingId, options }),
|
||||
onSuccess: (_data, { settingId }) => {
|
||||
qc.invalidateQueries({ queryKey: api.dropdownSettings.list.queryKey() });
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.dropdownSettings.getById.queryKey({ id: settingId }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useAddDropdownOption = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
settingId,
|
||||
dto,
|
||||
}: {
|
||||
settingId: string;
|
||||
dto: CreateDropdownOptionDto;
|
||||
}) => api.dropdownSettings.addOption.call({ id: settingId, dto }),
|
||||
onSuccess: (_data, { settingId }) => {
|
||||
qc.invalidateQueries({ queryKey: api.dropdownSettings.list.queryKey() });
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.dropdownSettings.getById.queryKey({ id: settingId }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateDropdownOption = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
optionId,
|
||||
dto,
|
||||
}: {
|
||||
optionId: string;
|
||||
dto: UpdateDropdownOptionDto;
|
||||
}) => api.dropdownSettings.updateOption.call({ optionId, dto }),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({ queryKey: api.dropdownSettings.list.queryKey() }),
|
||||
});
|
||||
};
|
||||
|
||||
export const useRemoveDropdownOption = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (optionId: string) =>
|
||||
api.dropdownSettings.removeOption.call({ optionId }),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({ queryKey: api.dropdownSettings.list.queryKey() }),
|
||||
});
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { facilityService } from '@/services/facility.service';
|
||||
|
||||
export const facilityKeys = {
|
||||
all: ['facilities'] as const,
|
||||
list: () => ['facilities', 'list'] as const,
|
||||
detail: (id: string) => ['facilities', 'detail', id] as const,
|
||||
};
|
||||
|
||||
export function useFacilities() {
|
||||
return useQuery({
|
||||
queryKey: facilityKeys.list(),
|
||||
queryFn: () => facilityService.list().then((r) => r.data),
|
||||
});
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { api } from "@/services/api";
|
||||
import type {
|
||||
CreateFileUploadFieldDto,
|
||||
CreateFileUploadSettingDto,
|
||||
UpdateFileUploadFieldDto,
|
||||
UpdateFileUploadSettingDto,
|
||||
} from "@/types/fileUploadSettings";
|
||||
|
||||
/* ----------------------------- Mutations ----------------------------- */
|
||||
|
||||
export const useCreateFileUploadSetting = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (dto: CreateFileUploadSettingDto) =>
|
||||
api.fileUploadSettings.create.call(dto),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.list.queryKey(),
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateFileUploadSetting = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
dto,
|
||||
}: {
|
||||
id: string;
|
||||
dto: UpdateFileUploadSettingDto;
|
||||
}) => api.fileUploadSettings.update.call({ id, dto }),
|
||||
onSuccess: (_data, { id }) => {
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.list.queryKey(),
|
||||
});
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.getById.queryKey({ id }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteFileUploadSetting = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.fileUploadSettings.remove.call({ id }),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.list.queryKey(),
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
export const useReplaceFileUploadFields = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
settingId,
|
||||
fields,
|
||||
}: {
|
||||
settingId: string;
|
||||
fields: CreateFileUploadFieldDto[];
|
||||
}) => api.fileUploadSettings.replaceFields.call({ id: settingId, fields }),
|
||||
onSuccess: (_data, { settingId }) => {
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.list.queryKey(),
|
||||
});
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.getById.queryKey({ id: settingId }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useAddFileUploadField = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
settingId,
|
||||
dto,
|
||||
}: {
|
||||
settingId: string;
|
||||
dto: CreateFileUploadFieldDto;
|
||||
}) => api.fileUploadSettings.addField.call({ settingId, dto }),
|
||||
onSuccess: (_data, { settingId }) => {
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.list.queryKey(),
|
||||
});
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.getById.queryKey({ id: settingId }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateFileUploadField = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
fieldId,
|
||||
dto,
|
||||
}: {
|
||||
fieldId: string;
|
||||
dto: UpdateFileUploadFieldDto;
|
||||
}) => api.fileUploadSettings.updateField.call({ fieldId, dto }),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.list.queryKey(),
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
export const useRemoveFileUploadField = () => {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (fieldId: string) =>
|
||||
api.fileUploadSettings.removeField.call({ fieldId }),
|
||||
onSuccess: () =>
|
||||
qc.invalidateQueries({
|
||||
queryKey: api.fileUploadSettings.list.queryKey(),
|
||||
}),
|
||||
});
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { locomotivesService } from '@/services/locomotives.service';
|
||||
|
||||
export const locomotiveKeys = {
|
||||
all: ['locomotives'] as const,
|
||||
details: () => [...locomotiveKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...locomotiveKeys.details(), id] as const,
|
||||
};
|
||||
|
||||
export function useLocomotives() {
|
||||
return useQuery({
|
||||
queryKey: locomotiveKeys.all,
|
||||
queryFn: () => locomotivesService.getAll().then((response) => response.data),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateLocomotive() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: locomotivesService.create,
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: locomotiveKeys.all }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateLocomotive() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: Record<string, unknown> }) =>
|
||||
locomotivesService.update(id, data),
|
||||
onSuccess: (_, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: locomotiveKeys.all });
|
||||
qc.invalidateQueries({ queryKey: locomotiveKeys.detail(id) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDecommissionLocomotive() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: locomotivesService.decommission,
|
||||
onSuccess: (_, id) => {
|
||||
qc.invalidateQueries({ queryKey: locomotiveKeys.all });
|
||||
qc.invalidateQueries({ queryKey: locomotiveKeys.detail(id) });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
paymentsService,
|
||||
type PaymentListFilter,
|
||||
} from "@/services/payments.service";
|
||||
|
||||
export function usePaymentList(filter?: PaymentListFilter, enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: ["payments", "list", filter ?? {}],
|
||||
queryFn: () => paymentsService.list(filter),
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function usePaymentSummary(enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: ["payments", "summary"],
|
||||
queryFn: () => paymentsService.getSummary(),
|
||||
staleTime: 30_000,
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { routesService } from '@/services/routes.service';
|
||||
|
||||
export const routeKeys = {
|
||||
all: ['routes'] as const,
|
||||
yards: ['routes', 'yards'] as const,
|
||||
details: () => [...routeKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...routeKeys.details(), id] as const,
|
||||
};
|
||||
|
||||
export function useRoutes() {
|
||||
return useQuery({
|
||||
queryKey: routeKeys.all,
|
||||
queryFn: () => routesService.getAll().then((response) => response.data),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRouteYards() {
|
||||
return useQuery({
|
||||
queryKey: routeKeys.yards,
|
||||
queryFn: () => routesService.getYards().then((response) => response.data.data),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateRoute() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: routesService.create,
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: routeKeys.all }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateRoute() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: Record<string, unknown> }) =>
|
||||
routesService.update(id, data),
|
||||
onSuccess: (_, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: routeKeys.all });
|
||||
qc.invalidateQueries({ queryKey: routeKeys.detail(id) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeactivateRoute() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: routesService.deactivate,
|
||||
onSuccess: (_, id) => {
|
||||
qc.invalidateQueries({ queryKey: routeKeys.all });
|
||||
qc.invalidateQueries({ queryKey: routeKeys.detail(id) });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
import {
|
||||
signaturesService,
|
||||
type SaveSignaturePayload,
|
||||
} from "@/services/signatures.service";
|
||||
|
||||
const SAVED_SIGNATURE_KEY = ["me", "signature"] as const;
|
||||
|
||||
export function useMySignature() {
|
||||
return useQuery({
|
||||
queryKey: SAVED_SIGNATURE_KEY,
|
||||
queryFn: () => signaturesService.getMySignature(),
|
||||
staleTime: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useSaveSignature() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (payload: SaveSignaturePayload) =>
|
||||
signaturesService.saveMySignature(payload),
|
||||
onSuccess: () => {
|
||||
toast.success("Signature saved");
|
||||
void qc.invalidateQueries({ queryKey: SAVED_SIGNATURE_KEY });
|
||||
},
|
||||
onError: () => toast.error("Failed to save signature"),
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { trainSchedulingService } from '@/services/trainScheduling.service';
|
||||
import { QUERY_KEYS } from '@/constants/QUERY_KEYS';
|
||||
|
||||
/**
|
||||
* The 21 network stations / yards, sourced from the existing booking
|
||||
* reference-data API. Reused as the parent "Facility / Port" for warehouses.
|
||||
*/
|
||||
export function useStations() {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.stations(),
|
||||
queryFn: () => trainSchedulingService.getStations(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { trainService } from '@/services/trains.service';
|
||||
|
||||
export const trainKeys = {
|
||||
all: ['trains'] as const,
|
||||
lists: () => [...trainKeys.all, 'list'] as const,
|
||||
details: () => [...trainKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...trainKeys.details(), id] as const,
|
||||
};
|
||||
|
||||
export function useTrains() {
|
||||
return useQuery({ queryKey: trainKeys.lists(), queryFn: () => trainService.getAll().then(res => res.data) });
|
||||
}
|
||||
|
||||
export const useGetTrains = useTrains;
|
||||
|
||||
export function useTrain(id: string) {
|
||||
return useQuery({ queryKey: trainKeys.detail(id), queryFn: () => trainService.getById(id).then(res => res.data), enabled: !!id });
|
||||
}
|
||||
|
||||
export const useGetTrain = useTrain;
|
||||
|
||||
export function useCreateTrain() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: trainService.create, onSuccess: () => qc.invalidateQueries({ queryKey: trainKeys.lists() }) });
|
||||
}
|
||||
|
||||
export function useUpdateTrain() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: ({ id, data }: any) => trainService.update(id, data), onSuccess: (_, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: trainKeys.lists() });
|
||||
qc.invalidateQueries({ queryKey: trainKeys.detail(id) });
|
||||
} });
|
||||
}
|
||||
|
||||
export function useDeleteTrain() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: trainService.delete, onSuccess: () => qc.invalidateQueries({ queryKey: trainKeys.lists() }) });
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
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(filters?: WagonListFilters) {
|
||||
return useQuery({
|
||||
queryKey: wagonKeys.list(filters),
|
||||
queryFn: () => wagonService.getAll(filters ?? {}).then((res) => res.data),
|
||||
});
|
||||
}
|
||||
|
||||
export const useGetWagons = useWagons;
|
||||
|
||||
export function useWagonsByTrain(trainId: string) {
|
||||
return useQuery({ queryKey: wagonKeys.byTrain(trainId), queryFn: () => wagonService.getByTrain(trainId).then(res => res.data), enabled: !!trainId });
|
||||
}
|
||||
|
||||
export function useWagon(id: string) {
|
||||
return useQuery({ queryKey: wagonKeys.detail(id), queryFn: () => wagonService.getById(id).then(res => res.data), enabled: !!id });
|
||||
}
|
||||
|
||||
export const useGetWagon = useWagon;
|
||||
|
||||
export function useAssignWagonToTrain() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: ({ wagonId, trainId, sequenceNumber }: any) => wagonService.assignToTrain(wagonId, trainId, sequenceNumber), onSuccess: (_, { trainId }) => qc.invalidateQueries({ queryKey: wagonKeys.byTrain(trainId) }) });
|
||||
}
|
||||
|
||||
export function useUnassignWagon() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: wagonService.unassign, onSuccess: () => qc.invalidateQueries({ queryKey: wagonKeys.all }) });
|
||||
}
|
||||
|
||||
export function useReorderWagons() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: ({ trainId, wagonIds }: any) => wagonService.reorder(trainId, wagonIds), onSuccess: (_, { trainId }) => qc.invalidateQueries({ queryKey: wagonKeys.byTrain(trainId) }) });
|
||||
}
|
||||
|
||||
export function useCreateWagon() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: wagonService.create, onSuccess: () => qc.invalidateQueries({ queryKey: wagonKeys.all }) });
|
||||
}
|
||||
|
||||
export function useUpdateWagon() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: ({ id, data }: any) => wagonService.update(id, data), onSuccess: (_, { id }) => {
|
||||
qc.invalidateQueries({ queryKey: wagonKeys.all });
|
||||
qc.invalidateQueries({ queryKey: wagonKeys.detail(id) });
|
||||
} });
|
||||
}
|
||||
|
||||
export function useDeleteWagon() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({ mutationFn: wagonService.delete, onSuccess: () => qc.invalidateQueries({ queryKey: wagonKeys.all }) });
|
||||
}
|
||||
Reference in New Issue
Block a user