From 6055f5c4ee5fb3898179b82e3303e9c0ef1c30b6 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Fri, 31 Mar 2023 18:31:21 +0530 Subject: [PATCH] fix: cycle list page mutation fix (#661) * fix: cycle list page mutation fix * fix: cycle mutation fix --- apps/app/components/cycles/modal.tsx | 21 ++++++++++++++++++++- apps/app/helpers/date-time.helper.ts | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/app/components/cycles/modal.tsx b/apps/app/components/cycles/modal.tsx index d73d667eb..19311cd08 100644 --- a/apps/app/components/cycles/modal.tsx +++ b/apps/app/components/cycles/modal.tsx @@ -77,7 +77,7 @@ export const CreateUpdateCycleModal: React.FC = ({ await cycleService .updateCycle(workspaceSlug as string, projectId as string, cycleId, payload) .then((res) => { - switch (getDateRangeStatus(res.start_date, res.end_date)) { + switch (getDateRangeStatus(data?.start_date, data?.end_date)) { case "completed": mutate(CYCLE_COMPLETE_LIST(projectId as string)); break; @@ -90,6 +90,25 @@ export const CreateUpdateCycleModal: React.FC = ({ default: mutate(CYCLE_DRAFT_LIST(projectId as string)); } + if ( + getDateRangeStatus(data?.start_date, data?.end_date) != + getDateRangeStatus(res.start_date, res.end_date) + ) { + switch (getDateRangeStatus(res.start_date, res.end_date)) { + case "completed": + mutate(CYCLE_COMPLETE_LIST(projectId as string)); + break; + case "current": + mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + break; + case "upcoming": + mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + break; + default: + mutate(CYCLE_DRAFT_LIST(projectId as string)); + } + } + handleClose(); setToastAlert({ diff --git a/apps/app/helpers/date-time.helper.ts b/apps/app/helpers/date-time.helper.ts index 24ef2a7bf..397e87c9d 100644 --- a/apps/app/helpers/date-time.helper.ts +++ b/apps/app/helpers/date-time.helper.ts @@ -89,7 +89,7 @@ export const timeAgo = (time: any) => { return time; }; -export const getDateRangeStatus = (startDate: string | null, endDate: string | null) => { +export const getDateRangeStatus = (startDate: string | null | undefined, endDate: string | null | undefined) => { if (!startDate || !endDate) return "draft"; const today = renderDateFormat(new Date());