mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
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
|
// 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,24 +64,33 @@ 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) => {
|
||||||
await cyclesService
|
if (isDateGreaterThanToday(payload.end_date)) {
|
||||||
.cycleDateCheck(workspaceSlug as string, projectId as string, payload)
|
await cyclesService
|
||||||
.then((res) => {
|
.cycleDateCheck(workspaceSlug as string, projectId as string, payload)
|
||||||
if (res.status) {
|
.then((res) => {
|
||||||
setIsDateValid(true);
|
if (res.status) {
|
||||||
} else {
|
setIsDateValid(true);
|
||||||
setIsDateValid(false);
|
} else {
|
||||||
setToastAlert({
|
setIsDateValid(false);
|
||||||
type: "error",
|
setToastAlert({
|
||||||
title: "Error!",
|
type: "error",
|
||||||
message:
|
title: "Error!",
|
||||||
"You have a cycle already on the given dates, if you want to create your draft cycle you can do that by removing dates",
|
message:
|
||||||
});
|
"You have a cycle already on the given dates, if you want to create your draft cycle you can do that by removing dates",
|
||||||
}
|
});
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
})
|
||||||
console.log(err);
|
.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 =
|
const checkEmptyDate =
|
||||||
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user