diff --git a/apps/edr-freight-web/backoffice/src/components/trainScheduling/IntercityRideAlongPanel.tsx b/apps/edr-freight-web/backoffice/src/components/trainScheduling/IntercityRideAlongPanel.tsx index 275e2d9c9..e4512e42a 100644 --- a/apps/edr-freight-web/backoffice/src/components/trainScheduling/IntercityRideAlongPanel.tsx +++ b/apps/edr-freight-web/backoffice/src/components/trainScheduling/IntercityRideAlongPanel.tsx @@ -29,7 +29,10 @@ const parseError = (error: unknown, fallback: string) => { return message || (error as Error)?.message || fallback; }; -function fmt(n: number): string { +// A capacity axis can be null when the schedule's locomotive has no limit +// configured for it — render "—" instead of crashing on toFixed. +function fmt(n: number | null | undefined): string { + if (n == null) return "—"; return Number.isInteger(n) ? String(n) : n.toFixed(1); } @@ -43,13 +46,22 @@ function CapacityBadges({ capacity }: { capacity: IntercityCapacity | null }) { } return ( - 0 ? "teal" : "red"}> + 0 ? "teal" : "red"} + > {fmt(capacity.wagons)} wagons free - 0 ? "teal" : "red"}> + 0 ? "teal" : "red"} + > {fmt(capacity.weightTons)} t free - 0 ? "teal" : "red"}> + 0 ? "teal" : "red"} + > {fmt(capacity.lengthMeters)} m free diff --git a/apps/edr-freight-web/backoffice/src/types/trainScheduling.ts b/apps/edr-freight-web/backoffice/src/types/trainScheduling.ts index 97f14f1d8..99cc613a1 100644 --- a/apps/edr-freight-web/backoffice/src/types/trainScheduling.ts +++ b/apps/edr-freight-web/backoffice/src/types/trainScheduling.ts @@ -879,9 +879,12 @@ export interface CompositionRemovalEntry { // the train's remaining wagon/weight/length capacity. export interface IntercityCapacity { - wagons: number; - weightTons: number; - lengthMeters: number; + // Each axis can be null when the schedule's train/locomotive has no limit + // configured for it (e.g. no max length on the loco) — the API passes the + // gap through rather than inventing a number. + wagons: number | null; + weightTons: number | null; + lengthMeters: number | null; } export interface IntercityBookingRow {