Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fix issue #7361: Block users from entering date out of range" #7366

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Components/Common/DateInputV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ const DateInputV2: React.FC<Props> = ({
return true;
};

const isDateWithinLimits = (parsedDate: dayjs.Dayjs): boolean => {
if (parsedDate?.isValid()) {
if (
(max && parsedDate.toDate() > max) ||
(min && parsedDate.toDate() < min)
) {
Notification.Error({
msg: outOfLimitsErrorMessage ?? "Cannot select date out of range",
});
return false;
}
return true;
}
return false;
};

const isSelectedMonth = (month: number) =>
month === datePickerHeaderDate.getMonth();

Expand Down Expand Up @@ -261,7 +277,7 @@ const DateInputV2: React.FC<Props> = ({
onChange={(e) => {
setDisplayValue(e.target.value.replaceAll("/", ""));
const value = dayjs(e.target.value, "DD/MM/YYYY", true);
if (value.isValid()) {
if (isDateWithinLimits(value)) {
onChange(value.toDate());
close();
setIsOpen?.(false);
Expand Down
Loading