feat: date range status function added

This commit is contained in:
Anmol Singh Bhatia 2023-03-03 11:32:00 +05:30
parent 8a941d0d14
commit 02e4e58f19
3 changed files with 18 additions and 34 deletions

View File

@ -128,7 +128,7 @@ export const CycleDetailsSidebar: React.FC<Props> = ({
<Squares2X2Icon className="h-4 w-4 flex-shrink-0" />
{cycleStatus === "current"
? "In Progress"
: cycleStatus === "completed"
: cycleStatus === "past"
? "Completed"
: cycleStatus === "upcoming"
? "Upcoming"

View File

@ -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";
}
}

View File

@ -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<UserAuth> = (props) => {
@ -80,38 +79,9 @@ const SingleCycle: React.FC<UserAuth> = (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<CycleIssueResponse[]>(