2023-05-28 20:44:40 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-09-29 12:02:47 +00:00
|
|
|
import { FC } from "react";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-05-17 07:28:01 +00:00
|
|
|
// components
|
2023-09-29 12:02:47 +00:00
|
|
|
import { CyclesList } from "components/cycles";
|
2023-05-28 20:44:40 +00:00
|
|
|
|
2023-09-29 12:02:47 +00:00
|
|
|
export interface ICyclesView {
|
|
|
|
filter: "all" | "current" | "upcoming" | "draft" | "completed" | "incomplete";
|
|
|
|
view: "list" | "board" | "gantt";
|
|
|
|
}
|
2023-07-24 06:02:59 +00:00
|
|
|
|
2023-09-29 12:02:47 +00:00
|
|
|
export const CyclesView: FC<ICyclesView> = (props) => {
|
|
|
|
const { filter, view } = props;
|
|
|
|
// router
|
2023-05-28 20:44:40 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
2023-09-29 12:02:47 +00:00
|
|
|
// store
|
|
|
|
const { cycle: cycleStore } = useMobxStore();
|
|
|
|
|
|
|
|
useSWR(
|
|
|
|
workspaceSlug && projectId ? `CYCLES_LIST_${projectId}` : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => cycleStore.fetchCycles(workspaceSlug.toString(), projectId.toString(), filter)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
if (!projectId) {
|
|
|
|
return <></>;
|
|
|
|
}
|
2023-05-17 07:28:01 +00:00
|
|
|
return (
|
2023-05-20 12:00:15 +00:00
|
|
|
<>
|
2023-09-29 12:02:47 +00:00
|
|
|
{view === "list" && <CyclesList cycles={cycleStore.cycles[projectId?.toString()]} />}
|
|
|
|
{view === "board" && <CyclesList cycles={cycleStore.cycles[projectId?.toString()]} />}
|
|
|
|
{view === "gantt" && <CyclesList cycles={cycleStore.cycles[projectId?.toString()]} />}
|
2023-05-20 12:00:15 +00:00
|
|
|
</>
|
2023-05-17 07:28:01 +00:00
|
|
|
);
|
|
|
|
};
|