mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 04:08:11 +00:00
automation
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
Truck,
|
Truck,
|
||||||
Container,
|
Container,
|
||||||
Package,
|
Package,
|
||||||
|
PackageOpen,
|
||||||
//TrainTrack,
|
//TrainTrack,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
@@ -143,6 +144,11 @@ const buildSidebarSections = (demoItems: SidebarItem[]): SidebarSection[] => [
|
|||||||
href: "/dashboard/warehouse-inventory",
|
href: "/dashboard/warehouse-inventory",
|
||||||
icon: <Package />,
|
icon: <Package />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Arrival Queue",
|
||||||
|
href: "/dashboard/arrival-queue",
|
||||||
|
icon: <PackageOpen />,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "Loading Queue",
|
label: "Loading Queue",
|
||||||
href: "/dashboard/loading-queue",
|
href: "/dashboard/loading-queue",
|
||||||
|
|||||||
@@ -233,24 +233,32 @@ export function useArrivalQueue() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function useArrivalMutation<TArgs>(fn: (args: TArgs) => Promise<unknown>) {
|
function useArrivalInvalidation() {
|
||||||
const qc = useQueryClient();
|
const qc = useQueryClient();
|
||||||
return useMutation({
|
return () => {
|
||||||
mutationFn: fn,
|
qc.invalidateQueries({ queryKey: ['warehouse-inventory'] });
|
||||||
onSuccess: () => {
|
qc.invalidateQueries({ queryKey: warehouseKeys.all });
|
||||||
qc.invalidateQueries({ queryKey: ['warehouse-inventory'] });
|
};
|
||||||
qc.invalidateQueries({ queryKey: warehouseKeys.all });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAutoUnloadArrived = () =>
|
export function useAutoUnloadArrived() {
|
||||||
useArrivalMutation(() => warehouseService.autoUnloadArrived());
|
const onSuccess = useArrivalInvalidation();
|
||||||
export const useAutoLoadReady = () => useArrivalMutation(() => warehouseService.autoLoadReady());
|
return useMutation({ mutationFn: () => warehouseService.autoUnloadArrived(), onSuccess });
|
||||||
export const useUnloadBooking = () =>
|
}
|
||||||
useArrivalMutation((args: { bookingId: string; payload?: Record<string, unknown> }) =>
|
|
||||||
warehouseService.unloadBooking(args.bookingId, args.payload),
|
export function useAutoLoadReady() {
|
||||||
);
|
const onSuccess = useArrivalInvalidation();
|
||||||
|
return useMutation({ mutationFn: () => warehouseService.autoLoadReady(), onSuccess });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUnloadBooking() {
|
||||||
|
const onSuccess = useArrivalInvalidation();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (args: { bookingId: string; payload?: Record<string, unknown> }) =>
|
||||||
|
warehouseService.unloadBooking(args.bookingId, args.payload),
|
||||||
|
onSuccess,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useInspectionReports(inventoryId?: string) {
|
export function useInspectionReports(inventoryId?: string) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Badge, Button, Card, Container, Group, Stack, Table, Tabs, Text } from '@mantine/core';
|
import { Badge, Button, Card, Container, Group, Stack, Table, Tabs, Text } from '@mantine/core';
|
||||||
import { CreditCard, Eye } from 'lucide-react';
|
import { CreditCard, Eye, Truck } from 'lucide-react';
|
||||||
|
|
||||||
import Breadcrumbs from '@/components/ui/Breadcrumbs';
|
import Breadcrumbs from '@/components/ui/Breadcrumbs';
|
||||||
import {
|
import {
|
||||||
@@ -10,7 +10,8 @@ import {
|
|||||||
WarehouseHero,
|
WarehouseHero,
|
||||||
formatNumber,
|
formatNumber,
|
||||||
} from '@/components/warehouses';
|
} from '@/components/warehouses';
|
||||||
import { useWarehouseInventory } from '@/hooks/useWarehouses';
|
import { useAutoLoadReady, useWarehouseInventory } from '@/hooks/useWarehouses';
|
||||||
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import type { WarehouseInventoryItem } from '@/types/warehouse';
|
import type { WarehouseInventoryItem } from '@/types/warehouse';
|
||||||
|
|
||||||
const isPaid = (item: WarehouseInventoryItem) => item.booking?.status === 'PAID';
|
const isPaid = (item: WarehouseInventoryItem) => item.booking?.status === 'PAID';
|
||||||
@@ -25,11 +26,26 @@ const isPaid = (item: WarehouseInventoryItem) => item.booking?.status === 'PAID'
|
|||||||
*/
|
*/
|
||||||
export default function LoadingQueuePage() {
|
export default function LoadingQueuePage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { toast } = useToast();
|
||||||
|
const autoLoad = useAutoLoadReady();
|
||||||
const { data: readyData, isLoading: readyLoading } = useWarehouseInventory({
|
const { data: readyData, isLoading: readyLoading } = useWarehouseInventory({
|
||||||
status: 'READY_FOR_LOADING',
|
status: 'READY_FOR_LOADING',
|
||||||
});
|
});
|
||||||
const { data: loadedData, isLoading: loadedLoading } = useWarehouseInventory({ status: 'LOADED' });
|
const { data: loadedData, isLoading: loadedLoading } = useWarehouseInventory({ status: 'LOADED' });
|
||||||
|
|
||||||
|
const handleAutoLoad = async () => {
|
||||||
|
try {
|
||||||
|
const res = await autoLoad.mutateAsync();
|
||||||
|
const r = res.data;
|
||||||
|
toast({
|
||||||
|
title: 'Auto-load complete',
|
||||||
|
description: `Loaded ${r.loadedCount} PAID item(s); skipped ${r.skippedCount} (unpaid stay pending).`,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
toast({ variant: 'destructive', title: 'Auto-load failed' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const readyItems = readyData ?? [];
|
const readyItems = readyData ?? [];
|
||||||
const loadedItems = loadedData ?? [];
|
const loadedItems = loadedData ?? [];
|
||||||
|
|
||||||
@@ -48,6 +64,17 @@ export default function LoadingQueuePage() {
|
|||||||
subtitle="Manage bookings and inventory through the loading workflow."
|
subtitle="Manage bookings and inventory through the loading workflow."
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Group justify="flex-end">
|
||||||
|
<Button
|
||||||
|
color="green"
|
||||||
|
leftSection={<Truck size={16} />}
|
||||||
|
loading={autoLoad.isPending}
|
||||||
|
onClick={handleAutoLoad}
|
||||||
|
>
|
||||||
|
Auto Load Ready Items
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
|
||||||
<Card withBorder radius="md" padding="lg">
|
<Card withBorder radius="md" padding="lg">
|
||||||
<Tabs defaultValue="ready">
|
<Tabs defaultValue="ready">
|
||||||
<Tabs.List>
|
<Tabs.List>
|
||||||
|
|||||||
Reference in New Issue
Block a user