mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 07:38:10 +00:00
Merge freight/develop into Warehouses
This commit is contained in:
35
apps/edr-freight-web/backoffice/src/hooks/fleet/useFleet.ts
Normal file
35
apps/edr-freight-web/backoffice/src/hooks/fleet/useFleet.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
||||
import type { FleetResourceSlug } from "@/pages/fleet/config/resources";
|
||||
import { fleetService } from "@/services/fleet/fleet.service";
|
||||
|
||||
export function useFleetList(slug: FleetResourceSlug) {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.FLEET.list(slug),
|
||||
queryFn: () => fleetService.list(slug),
|
||||
});
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
@@ -26,6 +26,52 @@ export const useRuleEngineList = (
|
||||
queryFn: () => ruleEngineService.list(resource, params),
|
||||
});
|
||||
|
||||
const ORDER_LIST_PAGE_SIZE = 500;
|
||||
|
||||
export const useRuleEngineOrderList = (
|
||||
resource: RuleEngineResourceSlug,
|
||||
enabled: boolean,
|
||||
sortBy?: string,
|
||||
) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.RULE_ENGINE.orderList(resource),
|
||||
queryFn: () =>
|
||||
ruleEngineService.list(resource, {
|
||||
page: 1,
|
||||
pageSize: ORDER_LIST_PAGE_SIZE,
|
||||
sortBy,
|
||||
sortOrder: "ASC",
|
||||
}),
|
||||
enabled,
|
||||
});
|
||||
|
||||
export const useRuleEngineOrderMutations = (resource: RuleEngineResourceSlug) => {
|
||||
const qc = useQueryClient();
|
||||
|
||||
const reorder = useMutation({
|
||||
mutationFn: (payload: { ids: string[]; requiresDirectorApproval?: boolean }) =>
|
||||
ruleEngineService.reorder(resource, payload),
|
||||
onSuccess: async () => {
|
||||
toast.success("Order updated");
|
||||
await invalidateRuleEngineList(qc, resource);
|
||||
await qc.invalidateQueries({ queryKey: QUERY_KEYS.RULE_ENGINE.orderList(resource) });
|
||||
},
|
||||
onError: () => toast.error("Failed to update order"),
|
||||
});
|
||||
|
||||
const moveOrder = useMutation({
|
||||
mutationFn: ({ id, direction }: { id: string; direction: "up" | "down" }) =>
|
||||
ruleEngineService.moveOrder(resource, id, direction),
|
||||
onSuccess: async () => {
|
||||
await invalidateRuleEngineList(qc, resource);
|
||||
await qc.invalidateQueries({ queryKey: QUERY_KEYS.RULE_ENGINE.orderList(resource) });
|
||||
},
|
||||
onError: () => toast.error("Cannot move item further in that direction"),
|
||||
});
|
||||
|
||||
return { reorder, moveOrder };
|
||||
};
|
||||
|
||||
export const useCargoTypeParentOptions = (excludeId?: string, enabled = true) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.RULE_ENGINE.selectOptions("cargo-types"),
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
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,
|
||||
TrainScheduleFilters,
|
||||
TrainSchedulePreviewPayload,
|
||||
} from "@/types/trainScheduling";
|
||||
|
||||
export const useScheduleList = (freightType?: FreightType) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.schedules(),
|
||||
queryFn: () => trainSchedulingService.listSchedules(freightType),
|
||||
});
|
||||
|
||||
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 = () =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.locomotives(),
|
||||
queryFn: () => trainSchedulingService.getAvailableLocomotives(),
|
||||
});
|
||||
|
||||
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.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 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,
|
||||
});
|
||||
|
||||
return { create, preview, assign, unassign, pin, finalize, dispatch, cancel, invalidate };
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export * from '@/components/container_management/use-cargoes';
|
||||
@@ -1 +0,0 @@
|
||||
export * from '@/components/container_management/use-containers';
|
||||
52
apps/edr-freight-web/backoffice/src/hooks/useOverview.ts
Normal file
52
apps/edr-freight-web/backoffice/src/hooks/useOverview.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
||||
import { overviewService } from "@/services/overview.service";
|
||||
import type { OverviewRange } from "@/types/overview";
|
||||
|
||||
export function useOverview(range: OverviewRange = "30d") {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.OVERVIEW.dashboard(range),
|
||||
queryFn: () => overviewService.getDashboard(range),
|
||||
});
|
||||
}
|
||||
|
||||
export function useOverviewBookingsTab(range: OverviewRange, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.OVERVIEW.bookingsTab(range),
|
||||
queryFn: () => overviewService.getBookingsTab(range),
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function useOverviewBillingTab(range: OverviewRange, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.OVERVIEW.billingTab(range),
|
||||
queryFn: () => overviewService.getBillingTab(range),
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function useOverviewOperationsTab(enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.OVERVIEW.operationsTab(),
|
||||
queryFn: () => overviewService.getOperationsTab(),
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function useOverviewCustomersTab(range: OverviewRange, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.OVERVIEW.customersTab(range),
|
||||
queryFn: () => overviewService.getCustomersTab(range),
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function useOverviewStaffTab(range: OverviewRange, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: QUERY_KEYS.OVERVIEW.staffTab(range),
|
||||
queryFn: () => overviewService.getStaffTab(range),
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user