diff --git a/src/features/schedule/components/ScheduleStartPage.tsx b/src/features/schedule/components/ScheduleStartPage.tsx index a3634e86..199ca8ea 100644 --- a/src/features/schedule/components/ScheduleStartPage.tsx +++ b/src/features/schedule/components/ScheduleStartPage.tsx @@ -129,6 +129,11 @@ export const ScheduleStartPage: FC = () => { const scheduleMinDate = useRef(getScheduleMinDate()).current; const scheduleMaxDate = useRef(getScheduleMaxDate()).current; + // Same-cities validation mirrors ScheduleFilter (Angular's + // ScheduleFilterValidationService): reject departure === arrival with + // the shared translation key. + const [sameCitiesError, setSameCitiesError] = useState(null); + const handleSubmit = useCallback( (e: FormEvent) => { e.preventDefault(); @@ -137,6 +142,12 @@ export const ScheduleStartPage: FC = () => { const arr = arrivalCode.trim().toUpperCase(); if (!dep || !arr) return; + if (dep === arr) { + setSameCitiesError("SHARED.ARRIVAL-EQUALS-DEPARTURE-ERROR"); + return; + } + setSameCitiesError(null); + // Empty dates default to the current week (today → today + 7) so // the search proceeds even when the user leaves the placeholder // untouched. Mirrors Angular's "by default it's the current week" @@ -222,7 +233,10 @@ export const ScheduleStartPage: FC = () => { label={t("SHARED.DEPARTURE_CITY")} placeholder={t("SHARED.CITY_PLACEHOLDER")} value={departureCode} - onChange={setDepartureCode} + onChange={(code) => { + setDepartureCode(code); + if (sameCitiesError) setSameCitiesError(null); + }} dictionaries={dictionaries} testIdPrefix="schedule-departure" /> @@ -248,10 +262,21 @@ export const ScheduleStartPage: FC = () => { label={t("SHARED.ARRIVAL_CITY")} placeholder={t("SHARED.CITY_PLACEHOLDER")} value={arrivalCode} - onChange={setArrivalCode} + onChange={(code) => { + setArrivalCode(code); + if (sameCitiesError) setSameCitiesError(null); + }} dictionaries={dictionaries} testIdPrefix="schedule-arrival" /> + {sameCitiesError && ( +
+ {t(sameCitiesError)} +
+ )}