mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 15:18:11 +00:00
fix
This commit is contained in:
@@ -41,11 +41,24 @@ const mileLabel = (e: FleetHistoryEvent) =>
|
||||
const arrow = (from?: string | null, to?: string | null) =>
|
||||
`${from ?? "—"} → ${to ?? "—"}`;
|
||||
|
||||
const metaStr = (e: FleetHistoryEvent, key: string) => {
|
||||
const v = e.metadata?.[key];
|
||||
return typeof v === "string" && v ? v : null;
|
||||
};
|
||||
|
||||
function describe(e: FleetHistoryEvent, entity: "driver" | "vehicle") {
|
||||
const bookingRef =
|
||||
typeof e.metadata?.bookingRef === "string" ? e.metadata.bookingRef : null;
|
||||
const withBooking = (rest?: string) =>
|
||||
[bookingRef ? `Booking ${bookingRef}` : "", rest ?? ""]
|
||||
const vehiclePlate = metaStr(e, "vehiclePlate");
|
||||
const driverName = metaStr(e, "driverName") ?? (e.label || null);
|
||||
const bookingRef = metaStr(e, "bookingRef");
|
||||
|
||||
// Compose the detail line with whatever the current view doesn't already
|
||||
// know: on a driver's timeline show which vehicle; always show the booking.
|
||||
const detail = (extra?: string) =>
|
||||
[
|
||||
entity === "driver" && vehiclePlate ? `Vehicle ${vehiclePlate}` : "",
|
||||
bookingRef ? `Booking ${bookingRef}` : "",
|
||||
extra ?? "",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" · ");
|
||||
|
||||
@@ -65,20 +78,31 @@ function describe(e: FleetHistoryEvent, entity: "driver" | "vehicle") {
|
||||
case "DRIVER_ASSIGNED":
|
||||
return {
|
||||
icon: <UserPlus size={14} />,
|
||||
title:
|
||||
title: entity === "vehicle" ? "Driver assigned" : "Assigned to vehicle",
|
||||
text:
|
||||
entity === "vehicle"
|
||||
? `Driver assigned${e.label ? `: ${e.label}` : ""}`
|
||||
: "Assigned to a vehicle",
|
||||
text: "",
|
||||
? driverName
|
||||
? `Driver ${driverName}`
|
||||
: ""
|
||||
: vehiclePlate
|
||||
? `Vehicle ${vehiclePlate}`
|
||||
: "",
|
||||
};
|
||||
case "DRIVER_UNASSIGNED":
|
||||
return {
|
||||
icon: <UserMinus size={14} />,
|
||||
title:
|
||||
entity === "vehicle"
|
||||
? `Driver unassigned${e.label ? `: ${e.label}` : ""}`
|
||||
: "Unassigned from a vehicle",
|
||||
text: "",
|
||||
? "Driver unassigned"
|
||||
: "Unassigned from vehicle",
|
||||
text:
|
||||
entity === "vehicle"
|
||||
? driverName
|
||||
? `Driver ${driverName}`
|
||||
: ""
|
||||
: vehiclePlate
|
||||
? `Vehicle ${vehiclePlate}`
|
||||
: "",
|
||||
};
|
||||
case "VEHICLE_STATUS_CHANGED":
|
||||
return {
|
||||
@@ -96,19 +120,19 @@ function describe(e: FleetHistoryEvent, entity: "driver" | "vehicle") {
|
||||
return {
|
||||
icon: <Route size={14} />,
|
||||
title: `${mileLabel(e)}: vehicle assigned`,
|
||||
text: withBooking(e.label ? `Status: ${e.label}` : ""),
|
||||
text: detail(e.label ? `Status: ${e.label}` : ""),
|
||||
};
|
||||
case "MILE_VEHICLE_RELEASED":
|
||||
return {
|
||||
icon: <Route size={14} />,
|
||||
title: `${mileLabel(e)}: vehicle released`,
|
||||
text: withBooking(),
|
||||
text: detail(),
|
||||
};
|
||||
case "MILE_STATUS_CHANGED":
|
||||
return {
|
||||
icon: <Route size={14} />,
|
||||
title: `${mileLabel(e)} status`,
|
||||
text: withBooking(arrow(e.fromValue, e.toValue)),
|
||||
text: detail(arrow(e.fromValue, e.toValue)),
|
||||
};
|
||||
default:
|
||||
return { icon: <CircleDot size={14} />, title: e.eventType, text: "" };
|
||||
|
||||
Reference in New Issue
Block a user