ScheduleFilter: validate departure===arrival mismatch with inline error (Angular parity)
This commit is contained in:
@@ -111,6 +111,10 @@ export const ScheduleFilter: FC<ScheduleFilterProps> = ({
|
||||
]);
|
||||
const [directOnly, setDirectOnly] = useState(initialDirectOnly);
|
||||
const [returnFlights, setReturnFlights] = useState(initialReturnFlights);
|
||||
// Mirrors Angular ScheduleFilterValidationService: a single inline
|
||||
// error shown below the arrival input when the user submits with
|
||||
// departure === arrival. Cleared whenever either city changes.
|
||||
const [sameCitiesError, setSameCitiesError] = useState<string | null>(null);
|
||||
|
||||
const scheduleMinDate = useRef(getScheduleMinDate()).current;
|
||||
const scheduleMaxDate = useRef(getScheduleMaxDate()).current;
|
||||
@@ -127,6 +131,13 @@ export const ScheduleFilter: FC<ScheduleFilterProps> = ({
|
||||
const arr = arrival.trim().toUpperCase();
|
||||
if (!dep || !arr) return;
|
||||
|
||||
// Angular rejects same-code routes with SHARED.ARRIVAL-EQUALS-DEPARTURE-ERROR.
|
||||
if (dep === arr) {
|
||||
setSameCitiesError("SHARED.ARRIVAL-EQUALS-DEPARTURE-ERROR");
|
||||
return;
|
||||
}
|
||||
setSameCitiesError(null);
|
||||
|
||||
// Default to current week if no range provided.
|
||||
const now = new Date();
|
||||
const day = now.getDay();
|
||||
@@ -175,7 +186,10 @@ export const ScheduleFilter: FC<ScheduleFilterProps> = ({
|
||||
label={t("SHARED.DEPARTURE_CITY")}
|
||||
placeholder={t("SHARED.CITY_PLACEHOLDER")}
|
||||
value={departure}
|
||||
onChange={setDeparture}
|
||||
onChange={(code) => {
|
||||
setDeparture(code);
|
||||
if (sameCitiesError) setSameCitiesError(null);
|
||||
}}
|
||||
dictionaries={dictionaries}
|
||||
testIdPrefix="schedule-departure"
|
||||
/>
|
||||
@@ -198,10 +212,21 @@ export const ScheduleFilter: FC<ScheduleFilterProps> = ({
|
||||
label={t("SHARED.ARRIVAL_CITY")}
|
||||
placeholder={t("SHARED.CITY_PLACEHOLDER")}
|
||||
value={arrival}
|
||||
onChange={setArrival}
|
||||
onChange={(code) => {
|
||||
setArrival(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="calendar">
|
||||
<label className="label--filter">
|
||||
|
||||
Reference in New Issue
Block a user