OnlineBoardFilter: constrain Calendar to ±1/+7 day window (Angular boardMin/MaxDate parity)
This commit is contained in:
@@ -72,6 +72,24 @@ function isSameLocalDay(a: Date | null, b: Date | null): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
// Mirrors Angular AppSettings.boardSearchFrom (1 day back) and
|
||||
// boardSearchTo (7 days forward). Keeps the board-filter calendar to the
|
||||
// same ±1/+7 window Angular enforces, so users can't pick a date outside
|
||||
// the available online-board range.
|
||||
function getBoardMinDate(): Date {
|
||||
const d = new Date();
|
||||
d.setHours(0, 0, 0, 0);
|
||||
d.setDate(d.getDate() - 1);
|
||||
return d;
|
||||
}
|
||||
|
||||
function getBoardMaxDate(): Date {
|
||||
const d = new Date();
|
||||
d.setHours(0, 0, 0, 0);
|
||||
d.setDate(d.getDate() + 7);
|
||||
return d;
|
||||
}
|
||||
|
||||
export const OnlineBoardFilter: FC<OnlineBoardFilterProps> = ({
|
||||
initialDeparture,
|
||||
initialArrival,
|
||||
@@ -104,6 +122,9 @@ export const OnlineBoardFilter: FC<OnlineBoardFilterProps> = ({
|
||||
);
|
||||
const [timeRange, setTimeRange] = useState<[number, number]>([0, 1440]);
|
||||
|
||||
const boardMinDate = useRef(getBoardMinDate()).current;
|
||||
const boardMaxDate = useRef(getBoardMaxDate()).current;
|
||||
|
||||
// Swap the Calendar input's display text to the translated 'Сегодня'
|
||||
// label when the selected date is today — Angular ships this in its
|
||||
// date field and the raw 'DD.MM.YYYY' reads clinical in comparison.
|
||||
@@ -300,6 +321,8 @@ export const OnlineBoardFilter: FC<OnlineBoardFilterProps> = ({
|
||||
<Calendar
|
||||
value={flightDate}
|
||||
onChange={(e) => setFlightDate(e.value as Date | null)}
|
||||
minDate={boardMinDate}
|
||||
maxDate={boardMaxDate}
|
||||
dateFormat="dd.mm.yy"
|
||||
placeholder={t("SHARED.DATE_FORMAT")}
|
||||
showIcon
|
||||
@@ -402,6 +425,8 @@ export const OnlineBoardFilter: FC<OnlineBoardFilterProps> = ({
|
||||
<Calendar
|
||||
value={routeDate}
|
||||
onChange={(e) => setRouteDate(e.value as Date | null)}
|
||||
minDate={boardMinDate}
|
||||
maxDate={boardMaxDate}
|
||||
dateFormat="dd.mm.yy"
|
||||
placeholder={t("SHARED.DATE_FORMAT")}
|
||||
showIcon
|
||||
|
||||
Reference in New Issue
Block a user