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 664a23069..dd173ba3e 100644 --- a/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx @@ -1003,14 +1003,17 @@ const LastMilePage = () => { const delivered = row.original.status === "DELIVERED"; const releaseRow = pickupReadyByBooking.get(row.original.bookingId) ?? pickupReadyByBooking.get(bookingRef(row.original)); - const truckArrivalLabel = releaseRow?.releaseOrderReference ? "Truck Leaving" : "Truck Arrival"; // Only the current step's action is active; the rest stay disabled. // Step order: 0 Ready·1 Assign·2 Arrived·3 Leave·4 In-transit·5 Distance·6 Delivered. const activeStep = computeLastMileSteps(row.original, releaseRow).findIndex((s) => s.active); const canAdvance = activeStep === 0 || activeStep === 4 || activeStep === 6; const canAssignStep = activeStep === 1; - const canTruck = activeStep === 2 || activeStep === 3; const canDistance = activeStep === 5; + // Truck arrival/leaving are independent of the step sequence — each + // driven only by its own state: arrive once assigned & not arrived, + // leave once arrived & not departed. + const canArrive = assigned && !releaseRow?.releaseOrderReference; + const canLeave = Boolean(releaseRow?.releaseOrderReference) && !releaseRow?.releaseDate; return ( @@ -1046,10 +1049,17 @@ const LastMilePage = () => { } - disabled={!canTruck} + disabled={!canArrive} onClick={() => openTruckArrival(row.original)} > - {truckArrivalLabel} + Truck Arrival + + } + disabled={!canLeave} + onClick={() => openTruckArrival(row.original)} + > + Truck Leaving