From 40320d247a821c921d5c6c6e7aaa5625fa7959f7 Mon Sep 17 00:00:00 2001 From: natib21 Date: Mon, 29 Jun 2026 08:37:48 +0000 Subject: [PATCH] fix --- .../src/pages/operations/FirstMilePage.tsx | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/apps/edr-freight-web/backoffice/src/pages/operations/FirstMilePage.tsx b/apps/edr-freight-web/backoffice/src/pages/operations/FirstMilePage.tsx index 1e748cc51..ebec2323c 100644 --- a/apps/edr-freight-web/backoffice/src/pages/operations/FirstMilePage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/operations/FirstMilePage.tsx @@ -18,10 +18,12 @@ import { Button, Card, Checkbox, + DateInput, Divider, Group, Menu, Modal, + NumberInput, Select, SimpleGrid, Stack, @@ -327,6 +329,10 @@ const FirstMilePage = () => { const [acceptVehicleValue, setAcceptVehicleValue] = useState(null); const [bookingSearch, setBookingSearch] = useState(""); + const [distanceOpen, setDistanceOpen] = useState(false); + const [distanceValue, setDistanceValue] = useState(""); + const [distanceDate, setDistanceDate] = useState(null); + const { data: listData, isLoading } = useQuery({ queryKey: QUERY_KEYS.FIRST_MILE.list(), queryFn: async () => { @@ -379,6 +385,21 @@ const FirstMilePage = () => { }, }); + const updateDistanceMutation = useMutation({ + mutationFn: ({ id, exactKm }: { id: string; exactKm: number }) => + firstMileService.update(id, { exactKm }), + onSuccess: () => { + void qc.invalidateQueries({ queryKey: QUERY_KEYS.FIRST_MILE.ROOT }); + if (activeRecord) { + toast({ title: "Distance updated", description: `${bookingRef(activeRecord)} → ${distanceValue} km` }); + } + closeDistance(); + }, + onError: () => { + toast({ title: "Update failed", variant: "destructive" }); + }, + }); + const acceptMutation = useMutation({ mutationFn: async ({ reference, vehicleId }: { reference: string; vehicleId: string | null }) => { const res = await firstMileService.accept(reference); @@ -454,6 +475,29 @@ const FirstMilePage = () => { acceptMutation.mutate({ reference: selectedBooking.reference, vehicleId: acceptVehicleValue }); }; + const openDistance = (id: string) => { + setActiveId(id); + setDistanceValue(""); + setDistanceDate(new Date()); + setDistanceOpen(true); + }; + + const closeDistance = () => { + setDistanceOpen(false); + setActiveId(null); + setDistanceValue(""); + setDistanceDate(null); + }; + + const handleSaveDistance = () => { + const distance = parseFloat(distanceValue); + if (!activeId || isNaN(distance) || distance < 0) { + toast({ title: "Invalid distance", description: "Enter a valid distance value.", variant: "destructive" }); + return; + } + updateDistanceMutation.mutate({ id: activeId, exactKm: distance }); + }; + const matchesFilter = (r: FirstMileRecord) => { switch (statusFilter) { case "ALL": return true; @@ -726,6 +770,11 @@ const FirstMilePage = () => { > View detail + openDistance(row.original.id)} + > + Add Actual distance + {canPrint && ( } @@ -1030,6 +1079,59 @@ const FirstMilePage = () => { )} + + {/* Add Actual Distance modal */} + Add Actual Distance} + size="md" + radius="lg" + centered + > + + {activeRecord && ( + + + {bookingRef(activeRecord)} + + Customer + {customerName(activeRecord)} + + + Est. Distance (KM) + {activeRecord.estimatedKm ?? "—"} + + + + )} + setDistanceValue(String(v ?? ""))} + min={0} + step={0.1} + decimalScale={2} + /> + + + + + + + ); };