From f965734f3bf10c05478cb36039dbafcfa4609256 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia Date: Fri, 3 Mar 2023 13:49:19 +0530 Subject: [PATCH] fix: mutation fix and date range helper fn added --- apps/app/components/cycles/modal.tsx | 44 ++++++++++++++++++++++++-- apps/app/components/cycles/sidebar.tsx | 2 +- apps/app/helpers/date-time.helper.ts | 2 +- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/apps/app/components/cycles/modal.tsx b/apps/app/components/cycles/modal.tsx index fc829024b..a83d8ca93 100644 --- a/apps/app/components/cycles/modal.tsx +++ b/apps/app/components/cycles/modal.tsx @@ -12,10 +12,16 @@ import cycleService from "services/cycles.service"; import useToast from "hooks/use-toast"; // components import { CycleForm } from "components/cycles"; +// helper +import { getDateRangeStatus } from "helpers/date-time.helper"; // types import type { ICycle } from "types"; // fetch keys -import { CYCLE_LIST } from "constants/fetch-keys"; +import { + CYCLE_COMPLETE_LIST, + CYCLE_CURRENT_AND_UPCOMING_LIST, + CYCLE_DRAFT_LIST, +} from "constants/fetch-keys"; type CycleModalProps = { isOpen: boolean; @@ -37,7 +43,23 @@ export const CreateUpdateCycleModal: React.FC = ({ await cycleService .createCycle(workspaceSlug as string, projectId as string, payload) .then((res) => { - mutate(CYCLE_LIST(projectId as string)); + switch ( + res?.start_date && res.end_date + ? getDateRangeStatus(res?.start_date, res.end_date) + : "draft" + ) { + 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({ @@ -59,7 +81,23 @@ export const CreateUpdateCycleModal: React.FC = ({ await cycleService .updateCycle(workspaceSlug as string, projectId as string, cycleId, payload) .then((res) => { - mutate(CYCLE_LIST(projectId as string)); + switch ( + res?.start_date && res.end_date + ? getDateRangeStatus(res?.start_date, res.end_date) + : "draft" + ) { + 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/components/cycles/sidebar.tsx b/apps/app/components/cycles/sidebar.tsx index 46be61e8b..ce61afea6 100644 --- a/apps/app/components/cycles/sidebar.tsx +++ b/apps/app/components/cycles/sidebar.tsx @@ -128,7 +128,7 @@ export const CycleDetailsSidebar: React.FC = ({ {cycleStatus === "current" ? "In Progress" - : cycleStatus === "past" + : cycleStatus === "completed" ? "Completed" : cycleStatus === "upcoming" ? "Upcoming" diff --git a/apps/app/helpers/date-time.helper.ts b/apps/app/helpers/date-time.helper.ts index b7a815cae..1fdd58f58 100644 --- a/apps/app/helpers/date-time.helper.ts +++ b/apps/app/helpers/date-time.helper.ts @@ -95,7 +95,7 @@ export const getDateRangeStatus = (startDate: string , endDate: string ) => { const end = new Date(endDate); if (end < now) { - return "past"; + return "completed"; } else if (start <= now && end >= now) { return "current"; } else {