From 63accc8bd321673b415cec287601de9e4a82b775 Mon Sep 17 00:00:00 2001 From: Roba Boru Date: Wed, 15 Jul 2026 22:03:29 +0300 Subject: [PATCH] Fix booking detail for roundtrip --- .../portal/src/app/booking/detail/page.tsx | 359 +++++++----------- 1 file changed, 143 insertions(+), 216 deletions(-) diff --git a/apps/edr-passenger-web/portal/src/app/booking/detail/page.tsx b/apps/edr-passenger-web/portal/src/app/booking/detail/page.tsx index c0c9f56bb..a54ce795b 100644 --- a/apps/edr-passenger-web/portal/src/app/booking/detail/page.tsx +++ b/apps/edr-passenger-web/portal/src/app/booking/detail/page.tsx @@ -412,6 +412,103 @@ function BookingDetailContent() { return displayTotal / etbTotal; })(); + // Flight-style origin → train → destination timeline for a single leg's schedule. + // Shared by both the pending-payment "Trip Summary" card and the confirmed booking's + // "Journey Details" card so a round trip's outbound and return legs render identically — + // each of those cards calls this once per leg instead of hardcoding booking.schedule only. + const renderJourneyTimeline = (schedule: any) => ( +
+
+
+
+
+
+
+
+
+ {schedule?.departureAt ? formatTime(schedule.departureAt) : "--:--"} +
+
+ {schedule?.departureAt + ? `${format(toZonedDate(new Date(schedule.departureAt)), "EEE, MMM d")} · ${getTimePeriod(schedule.departureAt)}` + : "N/A"} +
+
+ {schedule?.origin?.name} +
+
+ {schedule?.origin?.city} +
+
+ +
+
+
+ + + + Train {schedule?.trainNumber} +
+
+
+ +
+
+ {schedule?.arrivalAt ? formatTime(schedule.arrivalAt) : "--:--"} +
+
+ {schedule?.arrivalAt + ? `${format(toZonedDate(new Date(schedule.arrivalAt)), "EEE, MMM d")} · ${getTimePeriod(schedule.arrivalAt)}` + : "N/A"} +
+
+ {schedule?.destination?.name} +
+
+ {schedule?.destination?.city} +
+
+
+
+ ); + + // Renders one or both legs' timelines with an "Outbound Journey"/"Return Journey" + // heading pair when the booking has a return leg, or a single "Your Journey" heading + // for one-way bookings — used by both the pending-payment and confirmed views. + const renderJourneyLegs = () => ( + <> +
+
+ + {isRoundTripBooking ? "Outbound Journey" : "Your Journey"} + + {booking.passengers?.[0]?.seat?.seatClass && ( + + {booking.passengers[0].seat.seatClass} + + )} +
+ {renderJourneyTimeline(booking.schedule)} + + {isRoundTripBooking && booking.returnSchedule && ( +
+
+
+ + Return Journey + +
+ {renderJourneyTimeline(booking.returnSchedule)} +
+ )} + + ); + // Order summary card — mirrors /booking/payment's OrderSummary: fare breakdown per // passenger, Total with a loading spinner while a currency conversion is in flight, and // a note confirming what will actually be charged once a payment method is selected. @@ -586,137 +683,62 @@ function BookingDetailContent() { Trip Summary -
-
- - Your Journey - - {booking.passengers?.[0]?.seat?.seatClass && ( - - {booking.passengers[0].seat.seatClass} - - )} -
- - {/* Flight-style timeline */} -
- {/* Left column: Timeline with dots and line */} -
- {/* Origin dot */} -
- {/* Vertical line */} -
- {/* Destination dot */} -
-
- - {/* Right column: Content */} -
- {/* Origin */} -
-
- {booking.schedule?.departureAt - ? formatTime(booking.schedule.departureAt) - : "--:--"} -
-
- {booking.schedule?.departureAt - ? `${format(toZonedDate(new Date(booking.schedule.departureAt)), "EEE, MMM d")} · ${getTimePeriod(booking.schedule.departureAt)}` - : "N/A"} -
-
- {booking.schedule?.origin?.name} -
-
- {booking.schedule?.origin?.city} -
-
- - {/* Journey Info */} -
-
-
- - - - - Train {booking.schedule?.trainNumber} - -
- {booking.schedule?.trainName && ( - - {booking.schedule.trainName} - - )} -
-
- - {/* Destination */} -
-
- {booking.schedule?.arrivalAt - ? formatTime(booking.schedule.arrivalAt) - : "--:--"} -
-
- {booking.schedule?.arrivalAt - ? `${format(toZonedDate(new Date(booking.schedule.arrivalAt)), "EEE, MMM d")} · ${getTimePeriod(booking.schedule.arrivalAt)}` - : "N/A"} -
-
- {booking.schedule?.destination?.name} -
-
- {booking.schedule?.destination?.city} -
-
-
-
+ {renderJourneyLegs()}
- {booking.passengers?.length || 0} Passenger(s) + {groupedPassengers.length} Passenger(s)
- {booking.passengers?.map( - (passenger: any, idx: number) => ( -
-
-
- {passenger.fullName} -
-
- {passenger.category} • Coach{" "} - {passenger.seat?.coach} -
+ {groupedPassengers.map((passenger: any, idx: number) => ( +
+
+
+ {passenger.fullName}
-
-
- Seat {passenger.seat?.number} -
-
- {passenger.seat?.seatClass} -
+
+ {passenger.category}
- ), - )} + {isRoundTripBooking ? ( +
+ {( + [ + { legLabel: "Outbound", seat: passenger.outboundSeat }, + { legLabel: "Return", seat: passenger.returnSeat }, + ] as const + ).map(({ legLabel, seat }) => ( +
+
+ {legLabel} +
+
+ Seat {seat?.number ?? "--"} +
+
+ {seat?.seatClass} +
+
+ ))} +
+ ) : ( +
+
+ Seat {passenger.outboundSeat?.number} +
+
+ {passenger.outboundSeat?.seatClass} +
+
+ )} +
+ ))}
@@ -994,102 +1016,7 @@ function BookingDetailContent() { Journey Details -
-
- - Your Journey - - {booking.passengers?.[0]?.seat?.seatClass && ( - - {booking.passengers[0].seat.seatClass} - - )} -
- - {/* Flight-style timeline */} -
- {/* Left column: Timeline with dots and line */} -
- {/* Origin dot */} -
- {/* Vertical line */} -
- {/* Destination dot */} -
-
- - {/* Right column: Content */} -
- {/* Origin */} -
-
- {booking.schedule?.departureAt - ? formatTime(booking.schedule.departureAt) - : "--:--"} -
-
- {booking.schedule?.departureAt - ? `${format(toZonedDate(new Date(booking.schedule.departureAt)), "EEE, MMM d")} · ${getTimePeriod(booking.schedule.departureAt)}` - : "N/A"} -
-
- {booking.schedule?.origin?.name} -
-
- {booking.schedule?.origin?.city} -
-
- - {/* Journey Info */} -
-
-
- - - - - Train {booking.schedule?.trainNumber} - -
- {booking.schedule?.trainName && ( - - {booking.schedule.trainName} - - )} -
-
- - {/* Destination */} -
-
- {booking.schedule?.arrivalAt - ? formatTime(booking.schedule.arrivalAt) - : "--:--"} -
-
- {booking.schedule?.arrivalAt - ? `${format(toZonedDate(new Date(booking.schedule.arrivalAt)), "EEE, MMM d")} · ${getTimePeriod(booking.schedule.arrivalAt)}` - : "N/A"} -
-
- {booking.schedule?.destination?.name} -
-
- {booking.schedule?.destination?.city} -
-
-
-
+ {renderJourneyLegs()}