From 73baf97045dadc2e36cf6f9299dc573999355fbb Mon Sep 17 00:00:00 2001 From: Hagernesh Date: Wed, 8 Jul 2026 12:58:24 +0000 Subject: [PATCH] delivery approve notification --- .../src/modules/bookings/bookings.service.ts | 12 ++++++++++++ .../BookingDetailPage/ReadonlyBookingView.tsx | 1 + packages/types/src/freight/index.ts | 2 ++ 3 files changed, 15 insertions(+) diff --git a/apps/edr-freight-api/src/modules/bookings/bookings.service.ts b/apps/edr-freight-api/src/modules/bookings/bookings.service.ts index a5f25ad21..578e73278 100644 --- a/apps/edr-freight-api/src/modules/bookings/bookings.service.ts +++ b/apps/edr-freight-api/src/modules/bookings/bookings.service.ts @@ -1424,6 +1424,18 @@ export class BookingsService { schedule?.status ?? null; } + // A generated-but-unsigned handover means the customer must approve delivery. + // Surfaced so the portal shows "Approve delivery" as soon as the handover + // exists, independent of the truck-arrival flag. + const [pendingHandover] = await this.dataSource.query( + `SELECT 1 FROM freight.booking_handovers + WHERE booking_id = $1 AND signed_at IS NULL AND deleted_at IS NULL + LIMIT 1`, + [id], + ); + (booking as Booking & { handoverAwaitingSignature?: boolean }).handoverAwaitingSignature = + Boolean(pendingHandover); + return booking; } 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 40994d589..659f767c7 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 @@ -108,6 +108,7 @@ export function ReadonlyBookingView({ : status === "SELECTED_FOR_BATCH"); const canApproveDelivery = status === "COMPLETED" || + Boolean(booking.handoverAwaitingSignature) || (status === "TRUCK_ASSIGNED" && Boolean(booking.customerTruckArrivedAt)); const usesCustomerTruck = booking.tradeDirection === "IMPORT" diff --git a/packages/types/src/freight/index.ts b/packages/types/src/freight/index.ts index 7817e0a31..c5a1a364a 100644 --- a/packages/types/src/freight/index.ts +++ b/packages/types/src/freight/index.ts @@ -521,6 +521,8 @@ export interface IBooking extends BaseEntity { customerTruckContainerNumber?: string | null; customerTruckAssignedAt?: string | null; customerTruckArrivedAt?: string | null; + /** A handover has been generated for this booking and is awaiting the customer's signature. */ + handoverAwaitingSignature?: boolean; customsClearingEnabled?: boolean; // (multi-truck self-haul lives in ICustomerTruck[], fetched via the