mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
Fixing the round trip disabling dates
This commit is contained in:
@@ -40,13 +40,6 @@ async function bootstrap() {
|
||||
"x-delegator-position-id",
|
||||
"x-current-project-id",
|
||||
"x-current-position-id",
|
||||
// Headers sent by the freight-backoffice OKR/objective-service client
|
||||
// (withHeaders.tsx, signatureAndTeeterService.ts, useIncomingReport.ts)
|
||||
// under yet another naming convention — unprefixed "tenant-key"/"unit-id",
|
||||
// and "x-delegated-position-id" (delegated, not delegator).
|
||||
"tenant-key",
|
||||
"unit-id",
|
||||
"x-delegated-position-id",
|
||||
],
|
||||
exposedHeaders: ["Content-Disposition"],
|
||||
maxAge: 86400, // cache preflight for 24h to cut chatter in dev
|
||||
|
||||
@@ -758,6 +758,53 @@ export default function SearchPage() {
|
||||
}
|
||||
}, [departureDate, disabledDates, setValue, setError]);
|
||||
|
||||
// Same idea as the departure-date availability above, but for the return leg — which travels
|
||||
// destination -> origin, the reverse pair. Only fetched for round trips once both stations are
|
||||
// picked; deliberately unaware of which specific outbound schedule will end up chosen (that's
|
||||
// a searchTrips()-time concern via the latestOutboundArrival same-day-connection filter, not
|
||||
// something this pre-search picker can know).
|
||||
const { data: returnAvailableDates } = useQuery<AvailableDatesResponse>({
|
||||
queryKey: ["available-dates", destId, originId],
|
||||
queryFn: async () => {
|
||||
const from = new Date();
|
||||
const to = new Date();
|
||||
to.setDate(to.getDate() + AVAILABLE_DATES_RANGE_DAYS);
|
||||
return (await apiClient.get("/search/available-dates", {
|
||||
params: {
|
||||
originStationId: destId,
|
||||
destinationStationId: originId,
|
||||
from: toDateStr(from),
|
||||
to: toDateStr(to),
|
||||
},
|
||||
})) as AvailableDatesResponse;
|
||||
},
|
||||
enabled: !!originId && !!destId && tripType === "ROUND_TRIP",
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
|
||||
const returnDisabledDates = useMemo(() => {
|
||||
const set = new Set<string>();
|
||||
if (!returnAvailableDates?.routeExists) return set;
|
||||
for (const d of returnAvailableDates.dates) if (!d.available) set.add(d.date);
|
||||
return set;
|
||||
}, [returnAvailableDates]);
|
||||
|
||||
const returnMaxDate = originId && destId && tripType === "ROUND_TRIP" ? maxSearchDate : undefined;
|
||||
|
||||
// If the currently selected return date becomes unavailable (From/To changed, or the
|
||||
// availability query just resolved), clear it and surface an inline error — mirrors the
|
||||
// departure-date effect above.
|
||||
useEffect(() => {
|
||||
if (returnDate && returnDisabledDates.has(returnDate)) {
|
||||
setValue("returnDate", "");
|
||||
setError("returnDate", {
|
||||
type: "manual",
|
||||
message:
|
||||
"No trains run this route on the selected return date — please pick another date.",
|
||||
});
|
||||
}
|
||||
}, [returnDate, returnDisabledDates, setValue, setError]);
|
||||
|
||||
const saveRecent = useCallback((id: string) => {
|
||||
setRecentStationIds((prev) => {
|
||||
const next = [id, ...prev.filter((x) => x !== id)].slice(0, 5);
|
||||
@@ -1229,6 +1276,8 @@ export default function SearchPage() {
|
||||
? new Date(departureDate + "T00:00:00")
|
||||
: new Date()
|
||||
}
|
||||
maxDate={returnMaxDate}
|
||||
disabledDates={returnDisabledDates}
|
||||
placeholder="Return date"
|
||||
error={!!errors.returnDate}
|
||||
/>
|
||||
@@ -1574,6 +1623,8 @@ export default function SearchPage() {
|
||||
? new Date(departureDate + "T00:00:00")
|
||||
: new Date()
|
||||
}
|
||||
maxDate={returnMaxDate}
|
||||
disabledDates={returnDisabledDates}
|
||||
placeholder="Return date"
|
||||
/>
|
||||
{errors.returnDate && (
|
||||
|
||||
Reference in New Issue
Block a user