This commit is contained in:
natib21
2026-07-03 20:25:53 +00:00
parent 16bd7fabcc
commit 05f7fc254e

View File

@@ -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]);