import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; import { Tab } from "@headlessui/react"; import useSWR from "swr"; // hooks import useLocalStorage from "hooks/use-local-storage"; import useUserAuth from "hooks/use-user-auth"; // layouts import { ProjectAuthorizationWrapper } from "layouts/auth-layout-legacy"; // components import { CyclesView, ActiveCycleDetails, CreateUpdateCycleModal } from "components/cycles"; // ui import { Button } from "@plane/ui"; import { EmptyState } from "components/common"; import { Icon } from "components/ui"; import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; // icons import { PlusIcon } from "@heroicons/react/24/outline"; // images import emptyCycle from "public/empty-state/cycle.svg"; // types import { SelectCycleType } from "types"; import type { NextPage } from "next"; // helper import { truncateText } from "helpers/string.helper"; import { useMobxStore } from "lib/mobx/store-provider"; import { observer } from "mobx-react-lite"; // constants import { CYCLE_TAB_LIST, CYCLE_VIEWS } from "constants/cycle"; type ICycleAPIFilter = "all" | "current" | "upcoming" | "draft" | "completed" | "incomplete"; type ICycleView = "list" | "board" | "gantt"; const ProjectCyclesPage: NextPage = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store const { project: projectStore } = useMobxStore(); const projectDetails = projectId ? projectStore.project_details[projectId.toString()] : null; // states const [selectedCycle, setSelectedCycle] = useState(); const [createUpdateCycleModal, setCreateUpdateCycleModal] = useState(false); // local storage const { storedValue: cycleTab, setValue: setCycleTab } = useLocalStorage("cycle_tab", "all"); const { storedValue: cyclesView, setValue: setCyclesView } = useLocalStorage("cycle_view", "list"); // hooks const { user } = useUserAuth(); // api call fetch project details useSWR( workspaceSlug && projectId ? `PROJECT_DETAILS_${projectId}` : null, workspaceSlug && projectId ? () => { projectStore.fetchProjectDetails(workspaceSlug.toString(), projectId.toString()); } : null ); /** * Clearing form data after closing the modal */ useEffect(() => { if (createUpdateCycleModal) return; const timer = setTimeout(() => { setSelectedCycle(undefined); clearTimeout(timer); }, 500); }, [createUpdateCycleModal]); useEffect(() => { if (cycleTab === "draft" && cyclesView === "gantt") { setCyclesView("list"); } }, [cycleTab, cyclesView, setCyclesView]); return ( } right={ } > setCreateUpdateCycleModal(false)} data={selectedCycle} user={user} /> {projectDetails?.total_cycles === 0 ? (
, text: "New Cycle", onClick: () => { const e = new KeyboardEvent("keydown", { key: "q", }); document.dispatchEvent(e); }, }} />
) : ( i.key === cycleTab)} selectedIndex={CYCLE_TAB_LIST.findIndex((i) => i.key === cycleTab)} onChange={(i) => { try { setCycleTab(CYCLE_TAB_LIST[i].key); } catch (e) { setCycleTab(CYCLE_TAB_LIST[0].key); } }} >
{CYCLE_TAB_LIST.map((tab) => ( `border-b-2 p-4 text-sm font-medium outline-none ${ selected ? "border-custom-primary-100 text-custom-primary-100" : "border-transparent" }` } > {tab.name} ))}
{CYCLE_VIEWS.map((view) => { if (cycleTab === "active") return null; if (view.key === "gantt" && cycleTab === "draft") return null; return ( ); })}
{cycleTab && cyclesView && workspaceSlug && projectId && ( )} {cycleTab && cyclesView && workspaceSlug && projectId && ( )} {cycleTab && cyclesView && workspaceSlug && projectId && ( )} {cycleTab && cyclesView && workspaceSlug && projectId && ( )}
)}
); }); export default ProjectCyclesPage;