diff --git a/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx b/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx index 08166e5b8..60b11758c 100644 --- a/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx @@ -1,5 +1,13 @@ import { useMemo, useState } from "react"; -import { Check, Eye, Filter, MoreHorizontal, RefreshCw, Truck } from "lucide-react"; +import { + ArrowRight, + Check, + Eye, + Filter, + MoreHorizontal, + RefreshCw, + Truck, +} from "lucide-react"; import type { ColumnDef } from "@edr/ui-common"; import { DataTable, DataTableFooter, usePagination } from "@edr/ui-common"; import { @@ -52,6 +60,12 @@ const DELIVERY_STATUS_META: Record< DELIVERED: { label: "Delivered", color: "green" }, }; +// Forward-only lifecycle: Payment Pending → Ready to Transit → Delivered. +const NEXT_DELIVERY_STATUS: Partial> = { + PAYMENT_PENDING: "READY_TO_TRANSIT", + READY_TO_TRANSIT: "DELIVERED", +}; + // Single filter covering both the delivery lifecycle and assignment state. type StatusFilter = | "ALL" @@ -271,6 +285,20 @@ const LastMilePage = () => { closeAssign(); }; + const handleAdvanceStatus = (job: LastMileJob) => { + const next = NEXT_DELIVERY_STATUS[job.deliveryStatus]; + if (!next) return; + setJobs((current) => + current.map((item) => + item.id === job.id ? { ...item, deliveryStatus: next } : item, + ), + ); + toast({ + title: "Status updated", + description: `${job.bookingRef} → ${DELIVERY_STATUS_META[next].label}`, + }); + }; + const columns = useMemo((): ColumnDef[] => { const headerClassName = ruleEngineTable.headerCell; const cellClassName = ruleEngineTable.bodyCell; @@ -343,15 +371,26 @@ const LastMilePage = () => { meta: { headerClassName, cellClassName: `${cellClassName} whitespace-nowrap` }, cell: ({ row }) => { const isAssigned = row.original.status === "ASSIGNED"; + const nextStatus = NEXT_DELIVERY_STATUS[row.original.deliveryStatus]; return ( - + + } + disabled={!nextStatus} + onClick={() => handleAdvanceStatus(row.original)} + > + {nextStatus + ? `Mark ${DELIVERY_STATUS_META[nextStatus].label}` + : "Delivered"} + + } disabled={isAssigned}