mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +00:00
mile
This commit is contained in:
@@ -48,6 +48,7 @@ import {
|
|||||||
LAST_MILE_STATUSES,
|
LAST_MILE_STATUSES,
|
||||||
type LastMileApiStatus,
|
type LastMileApiStatus,
|
||||||
type LastMileRecord,
|
type LastMileRecord,
|
||||||
|
type LastMileVehicle,
|
||||||
lastMileService,
|
lastMileService,
|
||||||
} from "@/services/last-mile.service";
|
} from "@/services/last-mile.service";
|
||||||
import { vehiclesService } from "@/services/vehicles.service";
|
import { vehiclesService } from "@/services/vehicles.service";
|
||||||
@@ -797,17 +798,29 @@ const LastMilePage = () => {
|
|||||||
const assignVehicleOptions = useMemo(() => {
|
const assignVehicleOptions = useMemo(() => {
|
||||||
const opts = [...vehicleOptions];
|
const opts = [...vehicleOptions];
|
||||||
const seen = new Set(opts.map((o) => o.value));
|
const seen = new Set(opts.map((o) => o.value));
|
||||||
const current = [
|
const pushVehicle = (v?: LastMileVehicle | null) => {
|
||||||
...(activeRecord?.vehicleAssignments?.map((a) => a.vehicle) ?? []),
|
|
||||||
activeRecord?.vehicle,
|
|
||||||
];
|
|
||||||
for (const v of current) {
|
|
||||||
if (v && !seen.has(v.id)) {
|
if (v && !seen.has(v.id)) {
|
||||||
seen.add(v.id);
|
seen.add(v.id);
|
||||||
const parts = [`${v.manufacturer} ${v.model}`, v.plateNumber];
|
const parts = [`${v.manufacturer} ${v.model}`, v.plateNumber];
|
||||||
if (v.code) parts.unshift(v.code);
|
if (v.code) parts.unshift(v.code);
|
||||||
opts.push({ value: v.id, label: parts.join(" · ") });
|
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;
|
return opts;
|
||||||
}, [vehicleOptions, activeRecord]);
|
}, [vehicleOptions, activeRecord]);
|
||||||
|
|||||||
Reference in New Issue
Block a user