diff --git a/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/ReadonlyBookingView.tsx b/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/ReadonlyBookingView.tsx
index 43b9f6e79..7384bbc4d 100644
--- a/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/ReadonlyBookingView.tsx
+++ b/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/ReadonlyBookingView.tsx
@@ -222,7 +222,7 @@ export function ReadonlyBookingView({
-
+
>
}
right={
diff --git a/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/components/MileSummaryCard.tsx b/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/components/MileSummaryCard.tsx
index 5128ddecd..bfb57529f 100644
--- a/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/components/MileSummaryCard.tsx
+++ b/apps/edr-freight-web/portal/src/pages/bookings/BookingDetailPage/components/MileSummaryCard.tsx
@@ -1,6 +1,8 @@
import { Box, Group, Stack, Text } from "@mantine/core";
import { useQuery } from "@tanstack/react-query";
+import type { Freight } from "@edr/types";
+
import { bookingsService } from "@/services/bookings.service";
import type {
MileLegSummary,
@@ -81,11 +83,19 @@ function VehicleRow({ v }: { v: MileVehicleSummary }) {
);
}
-function LegBlock({ title, leg }: { title: string; leg: MileLegSummary }) {
- const fmtMoney = (n: number | null) =>
+function LegBlock({
+ title,
+ leg,
+ address,
+}: {
+ title: string;
+ leg: MileLegSummary | null;
+ address?: string | null;
+}) {
+ const fmtMoney = (n: number | null, currency: string) =>
n == null
? null
- : `${leg.currency} ${Number(n).toLocaleString(undefined, {
+ : `${currency} ${Number(n).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
@@ -96,10 +106,25 @@ function LegBlock({ title, leg }: { title: string; leg: MileLegSummary }) {
{title}
-
+ {leg ? (
+
+ ) : (
+
+ )}
- {leg.vehicles.length > 0 ? (
+ {address && (
+
+ {title.startsWith("First") ? "Pickup" : "Delivery"}:{" "}
+ {address}
+
+ )}
+
+ {!leg ? (
+
+ Requested — a vehicle and driver will be assigned soon.
+
+ ) : leg.vehicles.length > 0 ? (
{leg.vehicles.map((v, i) => (
@@ -111,36 +136,57 @@ function LegBlock({ title, leg }: { title: string; leg: MileLegSummary }) {
)}
-
-
- {leg.exactKm != null && (
-
- Total distance {leg.exactKm} km
-
- )}
- {leg.remainingPayment != null && leg.remainingPayment > 0 && (
-
- Balance {fmtMoney(leg.remainingPayment)}
+ {leg && (
+
+
+ {leg.exactKm != null && (
+
+ Total distance{" "}
+ {leg.exactKm} km
+
+ )}
+ {leg.remainingPayment != null && leg.remainingPayment > 0 && (
+
+ Balance{" "}
+
+ {fmtMoney(leg.remainingPayment, leg.currency)}
+
+
+ )}
+
+ {leg.invoiced && (
+
+ Invoiced
)}
- {leg.invoiced && (
-
- Invoiced
-
- )}
-
+ )}
);
}
-export function MileSummaryCard({ bookingId }: { bookingId: string }) {
+export function MileSummaryCard({ booking }: { booking: Freight.IBooking }) {
const { data } = useQuery({
- queryKey: ["booking-mile-summary", bookingId],
- queryFn: () => bookingsService.mileSummary(bookingId),
+ queryKey: ["booking-mile-summary", booking.id],
+ queryFn: () => bookingsService.mileSummary(booking.id),
});
- if (!data || (!data.firstMile && !data.lastMile)) return null;
+ const firstLeg = data?.firstMile ?? null;
+ const lastLeg = data?.lastMile ?? null;
+
+ // The backend doesn't persist an "enabled" flag — the presence of a
+ // pickup/delivery address is the request signal. Also show a leg once its
+ // record exists, regardless of address.
+ const showFirst = !!booking.firstMilePickupAddress || !!firstLeg;
+ const showLast = !!booking.lastMileDeliveryAddress || !!lastLeg;
+
+ if (!showFirst && !showLast) return null;
return (
@@ -148,8 +194,20 @@ export function MileSummaryCard({ bookingId }: { bookingId: string }) {
First & Last Mile
- {data.firstMile && }
- {data.lastMile && }
+ {showFirst && (
+
+ )}
+ {showLast && (
+
+ )}
);