forked from github/plane
fix: cycle date validation (#922)
This commit is contained in:
parent
e53847c59e
commit
d041d8be6b
@ -11,7 +11,11 @@ import useToast from "hooks/use-toast";
|
||||
// ui
|
||||
import { DateSelect, Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui";
|
||||
// helpers
|
||||
import { getDateRangeStatus, isDateRangeValid } from "helpers/date-time.helper";
|
||||
import {
|
||||
getDateRangeStatus,
|
||||
isDateGreaterThanToday,
|
||||
isDateRangeValid,
|
||||
} from "helpers/date-time.helper";
|
||||
// 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) : "";
|
||||
|
||||
const dateChecker = async (payload: any) => {
|
||||
if (isDateGreaterThanToday(payload.end_date)) {
|
||||
await cyclesService
|
||||
.cycleDateCheck(workspaceSlug as string, projectId as string, payload)
|
||||
.then((res) => {
|
||||
@ -78,6 +83,14 @@ export const CycleForm: React.FC<Props> = ({ handleFormSubmit, handleClose, stat
|
||||
.catch((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 =
|
||||
|
@ -177,6 +177,12 @@ export const renderShortTime = (date: string | Date) => {
|
||||
export const isDateRangeValid = (startDate: string, endDate: string) =>
|
||||
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) => {
|
||||
const date = new Date(dateString);
|
||||
const day = date.getDate();
|
||||
|
Loading…
Reference in New Issue
Block a user