fix: cycle date validation (#922)

This commit is contained in:
Anmol Singh Bhatia 2023-04-22 18:17:17 +05:30 committed by GitHub
parent e53847c59e
commit d041d8be6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 18 deletions

View File

@ -11,7 +11,11 @@ import useToast from "hooks/use-toast";
// ui // ui
import { DateSelect, Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui"; import { DateSelect, Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui";
// helpers // helpers
import { getDateRangeStatus, isDateRangeValid } from "helpers/date-time.helper"; import {
getDateRangeStatus,
isDateGreaterThanToday,
isDateRangeValid,
} from "helpers/date-time.helper";
// types // types
import { ICycle } from "types"; import { ICycle } from "types";
@ -60,6 +64,7 @@ export const CycleForm: React.FC<Props> = ({ handleFormSubmit, handleClose, stat
data?.start_date && data?.end_date ? getDateRangeStatus(data?.start_date, data?.end_date) : ""; data?.start_date && data?.end_date ? getDateRangeStatus(data?.start_date, data?.end_date) : "";
const dateChecker = async (payload: any) => { const dateChecker = async (payload: any) => {
if (isDateGreaterThanToday(payload.end_date)) {
await cyclesService await cyclesService
.cycleDateCheck(workspaceSlug as string, projectId as string, payload) .cycleDateCheck(workspaceSlug as string, projectId as string, payload)
.then((res) => { .then((res) => {
@ -78,6 +83,14 @@ export const CycleForm: React.FC<Props> = ({ handleFormSubmit, handleClose, stat
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
}); });
} else {
setIsDateValid(false);
setToastAlert({
type: "error",
title: "Error!",
message: "Unable to create cycle in past date. Please enter a valid date.",
});
}
}; };
const checkEmptyDate = const checkEmptyDate =

View File

@ -177,6 +177,12 @@ export const renderShortTime = (date: string | Date) => {
export const isDateRangeValid = (startDate: string, endDate: string) => export const isDateRangeValid = (startDate: string, endDate: string) =>
new Date(startDate) < new Date(endDate); new Date(startDate) < new Date(endDate);
export const isDateGreaterThanToday = (dateStr: string) =>{
const date = new Date(dateStr);
const today = new Date();
return date > today;
}
export const renderLongDateFormat = (dateString: string) => { export const renderLongDateFormat = (dateString: string) => {
const date = new Date(dateString); const date = new Date(dateString);
const day = date.getDate(); const day = date.getDate();