From d5e5006aabbcda8decaa33d132242dcb776c9731 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna <46787868+vamsikrishnamathala@users.noreply.github.com> Date: Thu, 18 Sep 2025 20:22:49 +0530 Subject: [PATCH] [WEB-4905]fix: cycle dates update (#7821) * fix: cycle dates update * fix: handled date clearing --- apps/web/core/components/cycles/modal.tsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/web/core/components/cycles/modal.tsx b/apps/web/core/components/cycles/modal.tsx index a53e3bcbf..b0fecdbed 100644 --- a/apps/web/core/components/cycles/modal.tsx +++ b/apps/web/core/components/cycles/modal.tsx @@ -1,7 +1,5 @@ "use client"; - import React, { useEffect, useState } from "react"; -import { format } from "date-fns"; import { mutate } from "swr"; // types import { CYCLE_TRACKER_EVENTS } from "@plane/constants"; @@ -9,6 +7,7 @@ import type { CycleDateCheckData, ICycle, TCycleTabOptions } from "@plane/types" // ui import { EModalPosition, EModalWidth, ModalCore, TOAST_TYPE, setToast } from "@plane/ui"; // hooks +import { renderFormattedPayloadDate } from "@plane/utils"; import { captureError, captureSuccess } from "@/helpers/event-tracker.helper"; import { useCycle } from "@/hooks/store/use-cycle"; import { useProject } from "@/hooks/store/use-project"; @@ -129,26 +128,31 @@ export const CycleCreateUpdateModal: React.FC = (props) => { const payload: Partial = { ...formData, + start_date: renderFormattedPayloadDate(formData.start_date) ?? null, + end_date: renderFormattedPayloadDate(formData.end_date) ?? null, }; let isDateValid: boolean = true; if (payload.start_date && payload.end_date) { - if (data?.start_date && data?.end_date) - isDateValid = await dateChecker(payload.project_id ?? projectId, { - start_date: format(payload.start_date, "yyyy-MM-dd"), - end_date: format(payload.end_date, "yyyy-MM-dd"), + if (data?.id) { + // Update existing cycle - always include cycle_id for validation + isDateValid = await dateChecker(projectId, { + start_date: payload.start_date, + end_date: payload.end_date, cycle_id: data.id, }); - else - isDateValid = await dateChecker(payload.project_id ?? projectId, { + } else { + // Create new cycle - no cycle_id needed + isDateValid = await dateChecker(projectId, { start_date: payload.start_date, end_date: payload.end_date, }); + } } if (isDateValid) { - if (data) await handleUpdateCycle(data.id, payload); + if (data?.id) await handleUpdateCycle(data.id, payload); else { await handleCreateCycle(payload).then(() => { setCycleTab("all");