ScheduleStartPage: add departure===arrival same-cities validation (Angular parity)
This commit is contained in:
@@ -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<string | null>(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 && (
|
||||
<div
|
||||
className="validation-tooltip"
|
||||
data-testid="schedule-same-cities-error"
|
||||
>
|
||||
{t(sameCitiesError)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="schedule-start__field">
|
||||
<label htmlFor="schedule-date-from">{t("SHARED.SCHEDULES_DATE")}</label>
|
||||
|
||||
Reference in New Issue
Block a user