Skip to content

Commit

Permalink
"Fix issue #7361: Block users from entering date out of range"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dareenfadel authored and Dareenfadel committed Mar 8, 2024
1 parent 83dc92f commit b381289
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 b381289

Please sign in to comment.