forked from github/plane
feat: date range status function added
This commit is contained in:
parent
8a941d0d14
commit
02e4e58f19
@ -128,7 +128,7 @@ export const CycleDetailsSidebar: React.FC<Props> = ({
|
|||||||
<Squares2X2Icon className="h-4 w-4 flex-shrink-0" />
|
<Squares2X2Icon className="h-4 w-4 flex-shrink-0" />
|
||||||
{cycleStatus === "current"
|
{cycleStatus === "current"
|
||||||
? "In Progress"
|
? "In Progress"
|
||||||
: cycleStatus === "completed"
|
: cycleStatus === "past"
|
||||||
? "Completed"
|
? "Completed"
|
||||||
: cycleStatus === "upcoming"
|
: cycleStatus === "upcoming"
|
||||||
? "Upcoming"
|
? "Upcoming"
|
||||||
|
@ -88,3 +88,17 @@ export const timeAgo = (time: any) => {
|
|||||||
}
|
}
|
||||||
return time;
|
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";
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ import { CustomMenu, EmptySpace, EmptySpaceItem, Spinner } from "components/ui";
|
|||||||
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
||||||
// helpers
|
// helpers
|
||||||
import { truncateText } from "helpers/string.helper";
|
import { truncateText } from "helpers/string.helper";
|
||||||
|
import { getDateRangeStatus } from "helpers/date-time.helper";
|
||||||
// types
|
// types
|
||||||
import { CycleIssueResponse, UserAuth } from "types";
|
import { CycleIssueResponse, UserAuth } from "types";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
@ -34,8 +35,6 @@ import {
|
|||||||
PROJECT_ISSUES_LIST,
|
PROJECT_ISSUES_LIST,
|
||||||
PROJECT_DETAILS,
|
PROJECT_DETAILS,
|
||||||
CYCLE_DETAILS,
|
CYCLE_DETAILS,
|
||||||
CYCLE_COMPLETE_LIST,
|
|
||||||
CYCLE_CURRENT_AND_UPCOMING_LIST,
|
|
||||||
} from "constants/fetch-keys";
|
} from "constants/fetch-keys";
|
||||||
|
|
||||||
const SingleCycle: React.FC<UserAuth> = (props) => {
|
const SingleCycle: React.FC<UserAuth> = (props) => {
|
||||||
@ -80,38 +79,9 @@ const SingleCycle: React.FC<UserAuth> = (props) => {
|
|||||||
: null
|
: 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 =
|
const cycleStatus =
|
||||||
checkForInCompleted && checkForInCompleted.length > 0
|
cycleDetails?.start_date && cycleDetails?.end_date
|
||||||
? "completed"
|
? getDateRangeStatus(cycleDetails?.start_date, cycleDetails?.end_date)
|
||||||
: checkForInProgress && checkForInProgress.length > 0
|
|
||||||
? "current"
|
|
||||||
: checkForUpcoming && checkForUpcoming.length > 0
|
|
||||||
? "upcoming"
|
|
||||||
: "draft";
|
: "draft";
|
||||||
|
|
||||||
const { data: cycleIssues } = useSWR<CycleIssueResponse[]>(
|
const { data: cycleIssues } = useSWR<CycleIssueResponse[]>(
|
||||||
|
Loading…
Reference in New Issue
Block a user