mirror of
https://github.com/gosticks/plane.git
synced 2025-10-16 12:45:33 +00:00
[WEB-4905]fix: cycle dates update (#7821)
* fix: cycle dates update * fix: handled date clearing
This commit is contained in:
parent
f7d5ca4f83
commit
d5e5006aab
@ -1,7 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { format } from "date-fns";
|
|
||||||
import { mutate } from "swr";
|
import { mutate } from "swr";
|
||||||
// types
|
// types
|
||||||
import { CYCLE_TRACKER_EVENTS } from "@plane/constants";
|
import { CYCLE_TRACKER_EVENTS } from "@plane/constants";
|
||||||
@ -9,6 +7,7 @@ import type { CycleDateCheckData, ICycle, TCycleTabOptions } from "@plane/types"
|
|||||||
// ui
|
// ui
|
||||||
import { EModalPosition, EModalWidth, ModalCore, TOAST_TYPE, setToast } from "@plane/ui";
|
import { EModalPosition, EModalWidth, ModalCore, TOAST_TYPE, setToast } from "@plane/ui";
|
||||||
// hooks
|
// hooks
|
||||||
|
import { renderFormattedPayloadDate } from "@plane/utils";
|
||||||
import { captureError, captureSuccess } from "@/helpers/event-tracker.helper";
|
import { captureError, captureSuccess } from "@/helpers/event-tracker.helper";
|
||||||
import { useCycle } from "@/hooks/store/use-cycle";
|
import { useCycle } from "@/hooks/store/use-cycle";
|
||||||
import { useProject } from "@/hooks/store/use-project";
|
import { useProject } from "@/hooks/store/use-project";
|
||||||
@ -129,26 +128,31 @@ export const CycleCreateUpdateModal: React.FC<CycleModalProps> = (props) => {
|
|||||||
|
|
||||||
const payload: Partial<ICycle> = {
|
const payload: Partial<ICycle> = {
|
||||||
...formData,
|
...formData,
|
||||||
|
start_date: renderFormattedPayloadDate(formData.start_date) ?? null,
|
||||||
|
end_date: renderFormattedPayloadDate(formData.end_date) ?? null,
|
||||||
};
|
};
|
||||||
|
|
||||||
let isDateValid: boolean = true;
|
let isDateValid: boolean = true;
|
||||||
|
|
||||||
if (payload.start_date && payload.end_date) {
|
if (payload.start_date && payload.end_date) {
|
||||||
if (data?.start_date && data?.end_date)
|
if (data?.id) {
|
||||||
isDateValid = await dateChecker(payload.project_id ?? projectId, {
|
// Update existing cycle - always include cycle_id for validation
|
||||||
start_date: format(payload.start_date, "yyyy-MM-dd"),
|
isDateValid = await dateChecker(projectId, {
|
||||||
end_date: format(payload.end_date, "yyyy-MM-dd"),
|
start_date: payload.start_date,
|
||||||
|
end_date: payload.end_date,
|
||||||
cycle_id: data.id,
|
cycle_id: data.id,
|
||||||
});
|
});
|
||||||
else
|
} else {
|
||||||
isDateValid = await dateChecker(payload.project_id ?? projectId, {
|
// Create new cycle - no cycle_id needed
|
||||||
|
isDateValid = await dateChecker(projectId, {
|
||||||
start_date: payload.start_date,
|
start_date: payload.start_date,
|
||||||
end_date: payload.end_date,
|
end_date: payload.end_date,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDateValid) {
|
if (isDateValid) {
|
||||||
if (data) await handleUpdateCycle(data.id, payload);
|
if (data?.id) await handleUpdateCycle(data.id, payload);
|
||||||
else {
|
else {
|
||||||
await handleCreateCycle(payload).then(() => {
|
await handleCreateCycle(payload).then(() => {
|
||||||
setCycleTab("all");
|
setCycleTab("all");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user