From 02e4e58f19f8386fb19d0150de8239dd345beefb Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia Date: Fri, 3 Mar 2023 11:32:00 +0530 Subject: [PATCH] feat: date range status function added --- apps/app/components/cycles/sidebar.tsx | 2 +- apps/app/helpers/date-time.helper.ts | 14 ++++++++ .../projects/[projectId]/cycles/[cycleId].tsx | 36 ++----------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/apps/app/components/cycles/sidebar.tsx b/apps/app/components/cycles/sidebar.tsx index ce61afea6..46be61e8b 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 === "completed" + : cycleStatus === "past" ? "Completed" : cycleStatus === "upcoming" ? "Upcoming" diff --git a/apps/app/helpers/date-time.helper.ts b/apps/app/helpers/date-time.helper.ts index 4d179ef0d..b7a815cae 100644 --- a/apps/app/helpers/date-time.helper.ts +++ b/apps/app/helpers/date-time.helper.ts @@ -88,3 +88,17 @@ export const timeAgo = (time: any) => { } return time; }; + +export const getDateRangeStatus = (startDate: string , endDate: string ) => { + const now = new Date(); + const start = new Date(startDate); + const end = new Date(endDate); + + if (end < now) { + return "past"; + } else if (start <= now && end >= now) { + return "current"; + } else { + return "upcoming"; + } +} \ No newline at end of file diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx index e4c1a5e94..efafd3ce3 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx @@ -25,6 +25,7 @@ import { CustomMenu, EmptySpace, EmptySpaceItem, Spinner } from "components/ui"; import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; // helpers import { truncateText } from "helpers/string.helper"; +import { getDateRangeStatus } from "helpers/date-time.helper"; // types import { CycleIssueResponse, UserAuth } from "types"; // fetch-keys @@ -34,8 +35,6 @@ import { PROJECT_ISSUES_LIST, PROJECT_DETAILS, CYCLE_DETAILS, - CYCLE_COMPLETE_LIST, - CYCLE_CURRENT_AND_UPCOMING_LIST, } from "constants/fetch-keys"; const SingleCycle: React.FC = (props) => { @@ -80,38 +79,9 @@ const SingleCycle: React.FC = (props) => { : null ); - const { data: currentAndUpcomingCycles } = useSWR( - workspaceSlug && projectId ? CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string) : null, - workspaceSlug && projectId - ? () => - cycleServices.getCurrentAndUpcomingCycles(workspaceSlug as string, projectId as string) - : null - ); - - const { data: completedCycles } = useSWR( - workspaceSlug && projectId ? CYCLE_COMPLETE_LIST(projectId as string) : null, - workspaceSlug && projectId - ? () => cycleServices.getCompletedCycles(workspaceSlug as string, projectId as string) - : null - ); - - const checkForInProgress = currentAndUpcomingCycles?.current_cycle?.filter( - (c) => c.id === cycleDetails?.id - ); - const checkForUpcoming = currentAndUpcomingCycles?.upcoming_cycle?.filter( - (c) => c.id === cycleDetails?.id - ); - const checkForInCompleted = completedCycles?.completed_cycles?.filter( - (c) => c.id === cycleDetails?.id - ); - const cycleStatus = - checkForInCompleted && checkForInCompleted.length > 0 - ? "completed" - : checkForInProgress && checkForInProgress.length > 0 - ? "current" - : checkForUpcoming && checkForUpcoming.length > 0 - ? "upcoming" + cycleDetails?.start_date && cycleDetails?.end_date + ? getDateRangeStatus(cycleDetails?.start_date, cycleDetails?.end_date) : "draft"; const { data: cycleIssues } = useSWR(