diff --git a/apps/app/components/cycles/active-cycle-details.tsx b/apps/app/components/cycles/active-cycle-details.tsx index 65c2e8b1b5a..7e8c8f7f798 100644 --- a/apps/app/components/cycles/active-cycle-details.tsx +++ b/apps/app/components/cycles/active-cycle-details.tsx @@ -40,20 +40,14 @@ import { } from "helpers/date-time.helper"; import { truncateText } from "helpers/string.helper"; // types -import { - CompletedCyclesResponse, - CurrentAndUpcomingCyclesResponse, - DraftCyclesResponse, - ICycle, - IIssue, -} from "types"; +import { ICycle, IIssue } from "types"; // fetch-keys import { CYCLE_COMPLETE_LIST, - CYCLE_CURRENT_AND_UPCOMING_LIST, - CYCLE_DETAILS, + CYCLE_CURRENT_LIST, CYCLE_DRAFT_LIST, CYCLE_ISSUES, + CYCLE_LIST, } from "constants/fetch-keys"; type TSingleStatProps = { @@ -111,51 +105,18 @@ export const ActiveCycleDetails: React.FC = ({ cycle, isComple const handleAddToFavorites = () => { if (!workspaceSlug || !projectId || !cycle) return; - switch (cycleStatus) { - case "current": - case "upcoming": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => ({ - current_cycle: (prevData?.current_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - upcoming_cycle: (prevData?.upcoming_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - case "completed": - mutate( - CYCLE_COMPLETE_LIST(projectId as string), - (prevData) => ({ - completed_cycles: (prevData?.completed_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - case "draft": - mutate( - CYCLE_DRAFT_LIST(projectId as string), - (prevData) => ({ - draft_cycles: (prevData?.draft_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - } + mutate( + CYCLE_CURRENT_LIST(projectId as string), + (prevData) => + (prevData ?? []).map((c) => ({ + ...c, + is_favorite: c.id === cycle.id ? true : c.is_favorite, + })), + false + ); + mutate( - CYCLE_DETAILS(projectId as string), + CYCLE_LIST(projectId as string), (prevData: any) => (prevData ?? []).map((c: any) => ({ ...c, @@ -180,51 +141,18 @@ export const ActiveCycleDetails: React.FC = ({ cycle, isComple const handleRemoveFromFavorites = () => { if (!workspaceSlug || !projectId || !cycle) return; - switch (cycleStatus) { - case "current": - case "upcoming": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => ({ - current_cycle: (prevData?.current_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - upcoming_cycle: (prevData?.upcoming_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - case "completed": - mutate( - CYCLE_COMPLETE_LIST(projectId as string), - (prevData) => ({ - completed_cycles: (prevData?.completed_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - case "draft": - mutate( - CYCLE_DRAFT_LIST(projectId as string), - (prevData) => ({ - draft_cycles: (prevData?.draft_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - } + mutate( + CYCLE_CURRENT_LIST(projectId as string), + (prevData) => + (prevData ?? []).map((c) => ({ + ...c, + is_favorite: c.id === cycle.id ? false : c.is_favorite, + })), + false + ); + mutate( - CYCLE_DETAILS(projectId as string), + CYCLE_LIST(projectId as string), (prevData: any) => (prevData ?? []).map((c: any) => ({ ...c, diff --git a/apps/app/components/cycles/completed-cycles.tsx b/apps/app/components/cycles/completed-cycles.tsx index 36ef691f5ed..f561f32d4d3 100644 --- a/apps/app/components/cycles/completed-cycles.tsx +++ b/apps/app/components/cycles/completed-cycles.tsx @@ -38,7 +38,10 @@ export const CompletedCycles: React.FC = ({ const { data: completedCycles } = useSWR( workspaceSlug && projectId ? CYCLE_COMPLETE_LIST(projectId as string) : null, workspaceSlug && projectId - ? () => cyclesService.getCompletedCycles(workspaceSlug as string, projectId as string) + ? () => + cyclesService.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "completed", + }) : null ); @@ -64,7 +67,7 @@ export const CompletedCycles: React.FC = ({ data={selectedCycleForDelete} /> {completedCycles ? ( - completedCycles.completed_cycles.length > 0 ? ( + completedCycles.length > 0 ? (
= ({
{cycleView === "list" && (
- {completedCycles.completed_cycles.map((cycle) => ( + {completedCycles.map((cycle) => (
= ({ )} {cycleView === "board" && (
- {completedCycles.completed_cycles.map((cycle) => ( + {completedCycles.map((cycle) => ( >; setCreateUpdateCycleModal: React.Dispatch>; cyclesCompleteList: ICycle[] | undefined; - currentAndUpcomingCycles: CurrentAndUpcomingCyclesResponse | undefined; - draftCycles: DraftCyclesResponse | undefined; + currentCycle: ICycle[] | undefined; + upcomingCycles: ICycle[] | undefined; + draftCycles: ICycle[] | undefined; }; export const CyclesView: React.FC = ({ setSelectedCycle, setCreateUpdateCycleModal, cyclesCompleteList, - currentAndUpcomingCycles, + currentCycle, + upcomingCycles, draftCycles, }) => { const { storedValue: cycleTab, setValue: setCycleTab } = useLocalStorage("cycleTab", "All"); @@ -182,8 +179,8 @@ export const CyclesView: React.FC = ({ {cyclesView !== "gantt_chart" && ( - {currentAndUpcomingCycles?.current_cycle?.[0] ? ( - + {currentCycle?.[0] ? ( + ) : ( = ({ {cyclesView === "list" && ( = ({ )} {cyclesView === "board" && ( )} {cyclesView === "gantt_chart" && ( - + )} @@ -226,7 +223,7 @@ export const CyclesView: React.FC = ({ {cyclesView === "list" && ( = ({ )} {cyclesView === "board" && ( >; @@ -28,10 +23,10 @@ type TConfirmCycleDeletionProps = { // fetch-keys import { CYCLE_COMPLETE_LIST, - CYCLE_CURRENT_AND_UPCOMING_LIST, - CYCLE_DETAILS, + CYCLE_CURRENT_LIST, CYCLE_DRAFT_LIST, CYCLE_LIST, + CYCLE_UPCOMING_LIST, } from "constants/fetch-keys"; import { getDateRangeStatus } from "helpers/date-time.helper"; @@ -60,63 +55,28 @@ export const DeleteCycleModal: React.FC = ({ await cycleService .deleteCycle(workspaceSlug as string, data.project, data.id) .then(() => { - switch (getDateRangeStatus(data.start_date, data.end_date)) { - case "completed": - mutate( - CYCLE_COMPLETE_LIST(projectId as string), - (prevData) => { - if (!prevData) return; + const cycleType = getDateRangeStatus(data.start_date, data.end_date); + const fetchKey = + cycleType === "current" + ? CYCLE_CURRENT_LIST(projectId as string) + : cycleType === "upcoming" + ? CYCLE_UPCOMING_LIST(projectId as string) + : cycleType === "completed" + ? CYCLE_COMPLETE_LIST(projectId as string) + : CYCLE_DRAFT_LIST(projectId as string); - return { - completed_cycles: prevData.completed_cycles?.filter( - (cycle) => cycle.id !== data?.id - ), - }; - }, - false - ); - break; - case "current": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => { - if (!prevData) return; - return { - current_cycle: prevData.current_cycle?.filter((c) => c.id !== data?.id), - upcoming_cycle: prevData.upcoming_cycle, - }; - }, - false - ); - break; - case "upcoming": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => { - if (!prevData) return; + mutate( + fetchKey, + (prevData) => { + if (!prevData) return; + + return prevData.filter((cycle) => cycle.id !== data?.id); + }, + false + ); - return { - current_cycle: prevData.current_cycle, - upcoming_cycle: prevData.upcoming_cycle?.filter((c) => c.id !== data?.id), - }; - }, - false - ); - break; - default: - mutate( - CYCLE_DRAFT_LIST(projectId as string), - (prevData) => { - if (!prevData) return; - return { - draft_cycles: prevData.draft_cycles?.filter((cycle) => cycle.id !== data?.id), - }; - }, - false - ); - } mutate( - CYCLE_DETAILS(projectId as string), + CYCLE_LIST(projectId as string), (prevData: any) => { if (!prevData) return; return prevData.filter((cycle: any) => cycle.id !== data?.id); diff --git a/apps/app/components/cycles/modal.tsx b/apps/app/components/cycles/modal.tsx index b3baacd658c..8a0c6b8add9 100644 --- a/apps/app/components/cycles/modal.tsx +++ b/apps/app/components/cycles/modal.tsx @@ -19,10 +19,11 @@ import type { ICycle } from "types"; // fetch keys import { CYCLE_COMPLETE_LIST, - CYCLE_CURRENT_AND_UPCOMING_LIST, - CYCLE_DETAILS, + CYCLE_CURRENT_LIST, CYCLE_DRAFT_LIST, CYCLE_INCOMPLETE_LIST, + CYCLE_LIST, + CYCLE_UPCOMING_LIST, } from "constants/fetch-keys"; type CycleModalProps = { @@ -50,16 +51,16 @@ export const CreateUpdateCycleModal: React.FC = ({ mutate(CYCLE_COMPLETE_LIST(projectId as string)); break; case "current": - mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + mutate(CYCLE_CURRENT_LIST(projectId as string)); break; case "upcoming": - mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + mutate(CYCLE_UPCOMING_LIST(projectId as string)); break; default: mutate(CYCLE_DRAFT_LIST(projectId as string)); } mutate(CYCLE_INCOMPLETE_LIST(projectId as string)); - mutate(CYCLE_DETAILS(projectId as string)); + mutate(CYCLE_LIST(projectId as string)); handleClose(); setToastAlert({ @@ -86,15 +87,15 @@ export const CreateUpdateCycleModal: React.FC = ({ mutate(CYCLE_COMPLETE_LIST(projectId as string)); break; case "current": - mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + mutate(CYCLE_CURRENT_LIST(projectId as string)); break; case "upcoming": - mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + mutate(CYCLE_UPCOMING_LIST(projectId as string)); break; default: mutate(CYCLE_DRAFT_LIST(projectId as string)); } - mutate(CYCLE_DETAILS(projectId as string)); + mutate(CYCLE_LIST(projectId as string)); if ( getDateRangeStatus(data?.start_date, data?.end_date) != getDateRangeStatus(res.start_date, res.end_date) @@ -104,10 +105,10 @@ export const CreateUpdateCycleModal: React.FC = ({ mutate(CYCLE_COMPLETE_LIST(projectId as string)); break; case "current": - mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + mutate(CYCLE_CURRENT_LIST(projectId as string)); break; case "upcoming": - mutate(CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string)); + mutate(CYCLE_UPCOMING_LIST(projectId as string)); break; default: mutate(CYCLE_DRAFT_LIST(projectId as string)); diff --git a/apps/app/components/cycles/select.tsx b/apps/app/components/cycles/select.tsx index 971c60dddd7..854749ec530 100644 --- a/apps/app/components/cycles/select.tsx +++ b/apps/app/components/cycles/select.tsx @@ -38,7 +38,10 @@ export const CycleSelect: React.FC = ({ const { data: cycles } = useSWR( workspaceSlug && projectId ? CYCLE_LIST(projectId) : null, workspaceSlug && projectId - ? () => cycleServices.getCycles(workspaceSlug as string, projectId) + ? () => + cycleServices.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "all", + }) : null ); diff --git a/apps/app/components/cycles/single-cycle-card.tsx b/apps/app/components/cycles/single-cycle-card.tsx index a5f6e8110e3..b6349b2adab 100644 --- a/apps/app/components/cycles/single-cycle-card.tsx +++ b/apps/app/components/cycles/single-cycle-card.tsx @@ -41,18 +41,14 @@ import { } from "helpers/date-time.helper"; import { copyTextToClipboard, truncateText } from "helpers/string.helper"; // types -import { - CompletedCyclesResponse, - CurrentAndUpcomingCyclesResponse, - DraftCyclesResponse, - ICycle, -} from "types"; +import { ICycle } from "types"; // fetch-keys import { CYCLE_COMPLETE_LIST, - CYCLE_CURRENT_AND_UPCOMING_LIST, - CYCLE_DETAILS, + CYCLE_CURRENT_LIST, CYCLE_DRAFT_LIST, + CYCLE_LIST, + CYCLE_UPCOMING_LIST, } from "constants/fetch-keys"; type TSingleStatProps = { @@ -108,51 +104,27 @@ export const SingleCycleCard: React.FC = ({ const handleAddToFavorites = () => { if (!workspaceSlug || !projectId || !cycle) return; - switch (cycleStatus) { - case "current": - case "upcoming": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => ({ - current_cycle: (prevData?.current_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - upcoming_cycle: (prevData?.upcoming_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - case "completed": - mutate( - CYCLE_COMPLETE_LIST(projectId as string), - (prevData) => ({ - completed_cycles: (prevData?.completed_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - case "draft": - mutate( - CYCLE_DRAFT_LIST(projectId as string), - (prevData) => ({ - draft_cycles: (prevData?.draft_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - } + const fetchKey = + cycleStatus === "current" + ? CYCLE_CURRENT_LIST(projectId as string) + : cycleStatus === "upcoming" + ? CYCLE_UPCOMING_LIST(projectId as string) + : cycleStatus === "completed" + ? CYCLE_COMPLETE_LIST(projectId as string) + : CYCLE_DRAFT_LIST(projectId as string); + + mutate( + fetchKey, + (prevData) => + (prevData ?? []).map((c) => ({ + ...c, + is_favorite: c.id === cycle.id ? true : c.is_favorite, + })), + false + ); + mutate( - CYCLE_DETAILS(projectId as string), + CYCLE_LIST(projectId as string), (prevData: any) => (prevData ?? []).map((c: any) => ({ ...c, @@ -177,51 +149,27 @@ export const SingleCycleCard: React.FC = ({ const handleRemoveFromFavorites = () => { if (!workspaceSlug || !projectId || !cycle) return; - switch (cycleStatus) { - case "current": - case "upcoming": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => ({ - current_cycle: (prevData?.current_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - upcoming_cycle: (prevData?.upcoming_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - case "completed": - mutate( - CYCLE_COMPLETE_LIST(projectId as string), - (prevData) => ({ - completed_cycles: (prevData?.completed_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - case "draft": - mutate( - CYCLE_DRAFT_LIST(projectId as string), - (prevData) => ({ - draft_cycles: (prevData?.draft_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - } + const fetchKey = + cycleStatus === "current" + ? CYCLE_CURRENT_LIST(projectId as string) + : cycleStatus === "upcoming" + ? CYCLE_UPCOMING_LIST(projectId as string) + : cycleStatus === "completed" + ? CYCLE_COMPLETE_LIST(projectId as string) + : CYCLE_DRAFT_LIST(projectId as string); + + mutate( + fetchKey, + (prevData) => + (prevData ?? []).map((c) => ({ + ...c, + is_favorite: c.id === cycle.id ? false : c.is_favorite, + })), + false + ); + mutate( - CYCLE_DETAILS(projectId as string), + CYCLE_LIST(projectId as string), (prevData: any) => (prevData ?? []).map((c: any) => ({ ...c, diff --git a/apps/app/components/cycles/single-cycle-list.tsx b/apps/app/components/cycles/single-cycle-list.tsx index a8976292e75..aa2bf097509 100644 --- a/apps/app/components/cycles/single-cycle-list.tsx +++ b/apps/app/components/cycles/single-cycle-list.tsx @@ -32,18 +32,14 @@ import { } from "helpers/date-time.helper"; import { copyTextToClipboard, truncateText } from "helpers/string.helper"; // types -import { - CompletedCyclesResponse, - CurrentAndUpcomingCyclesResponse, - DraftCyclesResponse, - ICycle, -} from "types"; +import { ICycle } from "types"; // fetch-keys import { CYCLE_COMPLETE_LIST, - CYCLE_CURRENT_AND_UPCOMING_LIST, - CYCLE_DETAILS, + CYCLE_CURRENT_LIST, CYCLE_DRAFT_LIST, + CYCLE_LIST, + CYCLE_UPCOMING_LIST, } from "constants/fetch-keys"; import { type } from "os"; @@ -142,51 +138,27 @@ export const SingleCycleList: React.FC = ({ const handleAddToFavorites = () => { if (!workspaceSlug || !projectId || !cycle) return; - switch (cycleStatus) { - case "current": - case "upcoming": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => ({ - current_cycle: (prevData?.current_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - upcoming_cycle: (prevData?.upcoming_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - case "completed": - mutate( - CYCLE_COMPLETE_LIST(projectId as string), - (prevData) => ({ - completed_cycles: (prevData?.completed_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - case "draft": - mutate( - CYCLE_DRAFT_LIST(projectId as string), - (prevData) => ({ - draft_cycles: (prevData?.draft_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? true : c.is_favorite, - })), - }), - false - ); - break; - } + const fetchKey = + cycleStatus === "current" + ? CYCLE_CURRENT_LIST(projectId as string) + : cycleStatus === "upcoming" + ? CYCLE_UPCOMING_LIST(projectId as string) + : cycleStatus === "completed" + ? CYCLE_COMPLETE_LIST(projectId as string) + : CYCLE_DRAFT_LIST(projectId as string); + + mutate( + fetchKey, + (prevData) => + (prevData ?? []).map((c) => ({ + ...c, + is_favorite: c.id === cycle.id ? true : c.is_favorite, + })), + false + ); + mutate( - CYCLE_DETAILS(projectId as string), + CYCLE_LIST(projectId as string), (prevData: any) => (prevData ?? []).map((c: any) => ({ ...c, @@ -211,51 +183,27 @@ export const SingleCycleList: React.FC = ({ const handleRemoveFromFavorites = () => { if (!workspaceSlug || !projectId || !cycle) return; - switch (cycleStatus) { - case "current": - case "upcoming": - mutate( - CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string), - (prevData) => ({ - current_cycle: (prevData?.current_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - upcoming_cycle: (prevData?.upcoming_cycle ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - case "completed": - mutate( - CYCLE_COMPLETE_LIST(projectId as string), - (prevData) => ({ - completed_cycles: (prevData?.completed_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - case "draft": - mutate( - CYCLE_DRAFT_LIST(projectId as string), - (prevData) => ({ - draft_cycles: (prevData?.draft_cycles ?? []).map((c) => ({ - ...c, - is_favorite: c.id === cycle.id ? false : c.is_favorite, - })), - }), - false - ); - break; - } + const fetchKey = + cycleStatus === "current" + ? CYCLE_CURRENT_LIST(projectId as string) + : cycleStatus === "upcoming" + ? CYCLE_UPCOMING_LIST(projectId as string) + : cycleStatus === "completed" + ? CYCLE_COMPLETE_LIST(projectId as string) + : CYCLE_DRAFT_LIST(projectId as string); + + mutate( + fetchKey, + (prevData) => + (prevData ?? []).map((c) => ({ + ...c, + is_favorite: c.id === cycle.id ? false : c.is_favorite, + })), + false + ); + mutate( - CYCLE_DETAILS(projectId as string), + CYCLE_LIST(projectId as string), (prevData: any) => (prevData ?? []).map((c: any) => ({ ...c, diff --git a/apps/app/components/cycles/transfer-issues-modal.tsx b/apps/app/components/cycles/transfer-issues-modal.tsx index c857e154ef6..8d44c14d02e 100644 --- a/apps/app/components/cycles/transfer-issues-modal.tsx +++ b/apps/app/components/cycles/transfer-issues-modal.tsx @@ -59,7 +59,10 @@ export const TransferIssuesModal: React.FC = ({ isOpen, handleClose }) => const { data: incompleteCycles } = useSWR( workspaceSlug && projectId ? CYCLE_INCOMPLETE_LIST(projectId as string) : null, workspaceSlug && projectId - ? () => cyclesService.getIncompleteCycles(workspaceSlug as string, projectId as string) + ? () => + cyclesService.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "incomplete", + }) : null ); diff --git a/apps/app/components/issues/sidebar-select/cycle.tsx b/apps/app/components/issues/sidebar-select/cycle.tsx index 3396dde271e..d9e7772a3fb 100644 --- a/apps/app/components/issues/sidebar-select/cycle.tsx +++ b/apps/app/components/issues/sidebar-select/cycle.tsx @@ -35,7 +35,10 @@ export const SidebarCycleSelect: React.FC = ({ const { data: incompleteCycles } = useSWR( workspaceSlug && projectId ? CYCLE_INCOMPLETE_LIST(projectId as string) : null, workspaceSlug && projectId - ? () => cyclesService.getIncompleteCycles(workspaceSlug as string, projectId as string) + ? () => + cyclesService.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "incomplete", + }) : null ); diff --git a/apps/app/constants/fetch-keys.ts b/apps/app/constants/fetch-keys.ts index 044dad38b87..5b286bcc1c6 100644 --- a/apps/app/constants/fetch-keys.ts +++ b/apps/app/constants/fetch-keys.ts @@ -83,8 +83,11 @@ export const CYCLE_ISSUES_WITH_PARAMS = (cycleId: string, params?: any) => { return `CYCLE_ISSUES_WITH_PARAMS_${cycleId.toUpperCase()}_${paramsKey.toUpperCase()}`; }; export const CYCLE_DETAILS = (cycleId: string) => `CYCLE_DETAILS_${cycleId.toUpperCase()}`; -export const CYCLE_CURRENT_AND_UPCOMING_LIST = (projectId: string) => - `CYCLE_CURRENT_AND_UPCOMING_LIST_${projectId.toUpperCase()}`; + +export const CYCLE_CURRENT_LIST = (projectId: string) => + `CYCLE_CURRENT_LIST${projectId.toUpperCase()}`; +export const CYCLE_UPCOMING_LIST = (projectId: string) => + `CYCLE_UPCOMING_LIST${projectId.toUpperCase()}`; export const CYCLE_DRAFT_LIST = (projectId: string) => `CYCLE_DRAFT_LIST_${projectId.toUpperCase()}`; export const CYCLE_COMPLETE_LIST = (projectId: string) => diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx index 4425014ac7a..3e5fafe6f28 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx @@ -56,7 +56,10 @@ const SingleCycle: React.FC = () => { const { data: cycles } = useSWR( workspaceSlug && projectId ? CYCLE_LIST(projectId as string) : null, workspaceSlug && projectId - ? () => cycleServices.getCycles(workspaceSlug as string, projectId as string) + ? () => + cycleServices.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "all", + }) : null ); diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/index.tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/index.tsx index 377d20faebc..fd6df9832af 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/index.tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/index.tsx @@ -21,10 +21,11 @@ import { SelectCycleType } from "types"; import type { NextPage } from "next"; // fetch-keys import { - CYCLE_CURRENT_AND_UPCOMING_LIST, CYCLE_DRAFT_LIST, PROJECT_DETAILS, - CYCLE_DETAILS, + CYCLE_UPCOMING_LIST, + CYCLE_CURRENT_LIST, + CYCLE_LIST, } from "constants/fetch-keys"; const ProjectCycles: NextPage = () => { @@ -44,21 +45,40 @@ const ProjectCycles: NextPage = () => { const { data: draftCycles } = useSWR( workspaceSlug && projectId ? CYCLE_DRAFT_LIST(projectId as string) : null, workspaceSlug && projectId - ? () => cycleService.getDraftCycles(workspaceSlug as string, projectId as string) + ? () => + cycleService.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "draft", + }) : null ); - const { data: currentAndUpcomingCycles } = useSWR( - workspaceSlug && projectId ? CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string) : null, + const { data: currentCycle } = useSWR( + workspaceSlug && projectId ? CYCLE_CURRENT_LIST(projectId as string) : null, workspaceSlug && projectId - ? () => cycleService.getCurrentAndUpcomingCycles(workspaceSlug as string, projectId as string) + ? () => + cycleService.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "current", + }) + : null + ); + + const { data: upcomingCycles } = useSWR( + workspaceSlug && projectId ? CYCLE_UPCOMING_LIST(projectId as string) : null, + workspaceSlug && projectId + ? () => + cycleService.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "upcoming", + }) : null ); const { data: cyclesCompleteList } = useSWR( - workspaceSlug && projectId ? CYCLE_DETAILS(projectId as string) : null, + workspaceSlug && projectId ? CYCLE_LIST(projectId as string) : null, workspaceSlug && projectId - ? () => cycleService.getCycles(workspaceSlug as string, projectId as string) + ? () => + cycleService.getCyclesWithParams(workspaceSlug as string, projectId as string, { + cycle_view: "all", + }) : null ); @@ -121,7 +141,8 @@ const ProjectCycles: NextPage = () => { setSelectedCycle={setSelectedCycle} setCreateUpdateCycleModal={setCreateUpdateCycleModal} cyclesCompleteList={cyclesCompleteList} - currentAndUpcomingCycles={currentAndUpcomingCycles} + currentCycle={currentCycle} + upcomingCycles={upcomingCycles} draftCycles={draftCycles} />
diff --git a/apps/app/services/cycles.service.ts b/apps/app/services/cycles.service.ts index 0e942fed0af..4d443a1109c 100644 --- a/apps/app/services/cycles.service.ts +++ b/apps/app/services/cycles.service.ts @@ -3,15 +3,7 @@ import APIService from "services/api.service"; import trackEventServices from "services/track-event.service"; // types -import type { - CycleIssueResponse, - CompletedCyclesResponse, - CurrentAndUpcomingCyclesResponse, - DraftCyclesResponse, - ICycle, - IIssue, - IIssueViewOptions, -} from "types"; +import type { ICycle, IIssue, IIssueViewOptions } from "types"; const { NEXT_PUBLIC_API_BASE_URL } = process.env; @@ -34,16 +26,14 @@ class ProjectCycleServices extends APIService { }); } - async getCycles(workspaceSlug: string, projectId: string): Promise { - return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - - async getIncompleteCycles(workspaceSlug: string, projectId: string): Promise { - return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/incomplete-cycles/`) + async getCyclesWithParams( + workspaceSlug: string, + projectId: string, + queries: any + ): Promise { + return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/`, { + params: queries, + }) .then((response) => response?.data) .catch((error) => { throw error?.response?.data; @@ -159,40 +149,6 @@ class ProjectCycleServices extends APIService { }); } - async getCurrentAndUpcomingCycles( - workspaceSlug: string, - projectId: string - ): Promise { - return this.get( - `/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/current-upcoming-cycles/` - ) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - - async getDraftCycles(workspaceSlug: string, projectId: string): Promise { - return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/draft-cycles/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - - async getCompletedCycles( - workspaceSlug: string, - projectId: string - ): Promise { - return this.get( - `/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/completed-cycles/` - ) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - async addCycleToFavorites( workspaceSlug: string, projectId: string, diff --git a/apps/app/types/cycles.d.ts b/apps/app/types/cycles.d.ts index ee4b2cef6a9..a8da352edc5 100644 --- a/apps/app/types/cycles.d.ts +++ b/apps/app/types/cycles.d.ts @@ -38,19 +38,6 @@ export interface ICycle { workspace_detail: IWorkspaceLite; } -export interface CurrentAndUpcomingCyclesResponse { - current_cycle: ICycle[]; - upcoming_cycle: ICycle[]; -} - -export interface DraftCyclesResponse { - draft_cycles: ICycle[]; -} - -export interface CompletedCyclesResponse { - completed_cycles: ICycle[]; -} - export interface CycleIssueResponse { id: string; issue_detail: IIssue;