Skip to content

Commit

Permalink
chore: module date validation (#3565)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolsinghbhatia authored Feb 5, 2024
1 parent 4041c5b commit 30aaec9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
3 changes: 1 addition & 2 deletions web/components/modules/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ModuleForm: React.FC<Props> = ({
const startDate = watch("start_date");
const targetDate = watch("target_date");

const minDate = startDate ? new Date(startDate) : new Date();
const minDate = startDate ? new Date(startDate) : null;
minDate?.setDate(minDate.getDate());

const maxDate = targetDate ? new Date(targetDate) : null;
Expand Down Expand Up @@ -159,7 +159,6 @@ export const ModuleForm: React.FC<Props> = ({
onChange={(date) => onChange(date ? renderFormattedPayloadDate(date) : null)}
buttonVariant="border-with-text"
placeholder="Start date"
minDate={new Date()}
maxDate={maxDate ?? undefined}
tabIndex={3}
/>
Expand Down
24 changes: 0 additions & 24 deletions web/components/modules/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,6 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
if (!watch("target_date") || watch("target_date") === "") endDateButtonRef.current?.click();

if (watch("start_date") && watch("target_date") && watch("start_date") !== "" && watch("start_date") !== "") {
if (!isDateGreaterThanToday(`${watch("target_date")}`)) {
setToastAlert({
type: "error",
title: "Error!",
message: "Unable to create module in past date. Please enter a valid date.",
});
reset({
...moduleDetails,
});
return;
}

submitChanges({
start_date: renderFormattedPayloadDate(`${watch("start_date")}`),
target_date: renderFormattedPayloadDate(`${watch("target_date")}`),
Expand All @@ -198,18 +186,6 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
if (!watch("start_date") || watch("start_date") === "") endDateButtonRef.current?.click();

if (watch("start_date") && watch("target_date") && watch("start_date") !== "" && watch("start_date") !== "") {
if (!isDateGreaterThanToday(`${watch("target_date")}`)) {
setToastAlert({
type: "error",
title: "Error!",
message: "Unable to create module in past date. Please enter a valid date.",
});
reset({
...moduleDetails,
});
return;
}

submitChanges({
start_date: renderFormattedPayloadDate(`${watch("start_date")}`),
target_date: renderFormattedPayloadDate(`${watch("target_date")}`),
Expand Down

0 comments on commit 30aaec9

Please sign in to comment.