From 05f7fc254ead239731bf9beb4e802fc0d9139658 Mon Sep 17 00:00:00 2001 From: natib21 Date: Fri, 3 Jul 2026 20:25:53 +0000 Subject: [PATCH] mile --- .../src/pages/operations/LastMilePage.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 06ac6d60a..21b57f0d5 100644 --- a/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/operations/LastMilePage.tsx @@ -48,6 +48,7 @@ import { LAST_MILE_STATUSES, type LastMileApiStatus, type LastMileRecord, + type LastMileVehicle, lastMileService, } from "@/services/last-mile.service"; import { vehiclesService } from "@/services/vehicles.service"; @@ -797,17 +798,29 @@ const LastMilePage = () => { const assignVehicleOptions = useMemo(() => { const opts = [...vehicleOptions]; const seen = new Set(opts.map((o) => o.value)); - const current = [ - ...(activeRecord?.vehicleAssignments?.map((a) => a.vehicle) ?? []), - activeRecord?.vehicle, - ]; - for (const v of current) { + const pushVehicle = (v?: LastMileVehicle | null) => { if (v && !seen.has(v.id)) { seen.add(v.id); const parts = [`${v.manufacturer} ${v.model}`, v.plateNumber]; if (v.code) parts.unshift(v.code); opts.push({ value: v.id, label: parts.join(" · ") }); } + }; + for (const a of activeRecord?.vehicleAssignments ?? []) pushVehicle(a.vehicle); + pushVehicle(activeRecord?.vehicle); + // Fallback: an assigned vehicle whose relation didn't load still needs an + // option so the reassign Select can render it as selected (not blank). + for (const a of activeRecord?.vehicleAssignments ?? []) { + if (!seen.has(a.vehicleId)) { + seen.add(a.vehicleId); + opts.push({ + value: a.vehicleId, + label: a.containerNumber ? `Assigned · ${a.containerNumber}` : "Assigned vehicle", + }); + } + } + if (activeRecord?.vehicleId && !seen.has(activeRecord.vehicleId)) { + opts.push({ value: activeRecord.vehicleId, label: "Assigned vehicle" }); } return opts; }, [vehicleOptions, activeRecord]);