import { Fragment, useCallback, useState, ReactElement } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Tab } from "@headlessui/react"; import { Plus } from "lucide-react"; // hooks import { useCycle, useUser } from "hooks/store"; import useLocalStorage from "hooks/use-local-storage"; // layouts import { AppLayout } from "layouts/app-layout"; // components import { CyclesHeader } from "components/headers"; import { CyclesView, ActiveCycleDetails, CycleCreateUpdateModal } from "components/cycles"; import { NewEmptyState } from "components/common/new-empty-state"; // ui import { Tooltip } from "@plane/ui"; // images import emptyCycle from "public/empty-state/empty_cycles.webp"; // types import { TCycleView, TCycleLayout } from "@plane/types"; import { NextPageWithLayout } from "lib/types"; // constants import { CYCLE_TAB_LIST, CYCLE_VIEW_LAYOUTS } from "constants/cycle"; import { EUserWorkspaceRoles } from "constants/workspace"; const ProjectCyclesPage: NextPageWithLayout = observer(() => { const [createModal, setCreateModal] = useState(false); // store hooks const { membership: { currentProjectRole }, } = useUser(); const { currentProjectCycleIds } = useCycle(); // router const router = useRouter(); const { workspaceSlug, projectId, peekCycle } = router.query; // local storage const { storedValue: cycleTab, setValue: setCycleTab } = useLocalStorage("cycle_tab", "active"); const { storedValue: cycleLayout, setValue: setCycleLayout } = useLocalStorage("cycle_layout", "list"); const handleCurrentLayout = useCallback( (_layout: TCycleLayout) => { setCycleLayout(_layout); }, [setCycleLayout] ); const handleCurrentView = useCallback( (_view: TCycleView) => { setCycleTab(_view); if (_view === "draft") handleCurrentLayout("list"); }, [handleCurrentLayout, setCycleTab] ); const totalCycles = currentProjectCycleIds?.length ?? 0; const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserWorkspaceRoles.MEMBER; if (!workspaceSlug || !projectId) return null; return ( <> setCreateModal(false)} /> {totalCycles === 0 ? (
, text: "Set your first cycle", onClick: () => { setCreateModal(true); }, }} disabled={!isEditingAllowed} />
) : ( i.key == cycleTab)} selectedIndex={CYCLE_TAB_LIST.findIndex((i) => i.key == cycleTab)} onChange={(i) => handleCurrentView(CYCLE_TAB_LIST[i]?.key ?? "active")} >
{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} ))} {cycleTab !== "active" && (
{CYCLE_VIEW_LAYOUTS.map((layout) => { if (layout.key === "gantt" && cycleTab === "draft") return null; return ( ); })}
)}
{cycleTab && cycleLayout && ( )} {cycleTab && cycleLayout && ( )} {cycleTab && cycleLayout && workspaceSlug && projectId && ( )} {cycleTab && cycleLayout && workspaceSlug && projectId && ( )}
)} ); }); ProjectCyclesPage.getLayout = function getLayout(page: ReactElement) { return ( } withProjectWrapper> {page} ); }; export default ProjectCyclesPage;