Skip to content

Commit

Permalink
"Fix issue #7361: Block users from entering date out of range" (#7366)
Browse files Browse the repository at this point in the history
Co-authored-by: Dareenfadel <https://github.com/Dareenfadel>
  • Loading branch information
Dareenfadel authored Mar 12, 2024
1 parent ecb4c04 commit 7261b67
Showing 1 changed file with 17 additions and 1 deletion.
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

0 comments on commit 7261b67

Please sign in to comment.