import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; // headless ui import { Tab } from "@headlessui/react"; // hooks import useLocalStorage from "hooks/use-local-storage"; import useUserAuth from "hooks/use-user-auth"; import useProjectDetails from "hooks/use-project-details"; // layouts import { ProjectAuthorizationWrapper } from "layouts/auth-layout"; // components import { ActiveCycleDetails, AllCyclesList, CompletedCyclesList, CreateUpdateCycleModal, DraftCyclesList, UpcomingCyclesList, } from "components/cycles"; // ui import { EmptyState, Icon, PrimaryButton } 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"; const tabsList = ["All", "Active", "Upcoming", "Completed", "Drafts"]; const cycleViews = [ { key: "list", icon: "list", }, { key: "board", icon: "dataset", }, { key: "gantt", icon: "view_timeline", }, ]; const ProjectCycles: NextPage = () => { const [selectedCycle, setSelectedCycle] = useState(); const [createUpdateCycleModal, setCreateUpdateCycleModal] = useState(false); const { storedValue: cycleTab, setValue: setCycleTab } = useLocalStorage("cycleTab", "All"); const { storedValue: cyclesView, setValue: setCyclesView } = useLocalStorage("cycleView", "list"); const currentTabValue = (tab: string | null) => { switch (tab) { case "All": return 0; case "Active": return 1; case "Upcoming": return 2; case "Completed": return 3; case "Drafts": return 4; default: return 0; } }; const router = useRouter(); const { workspaceSlug } = router.query; const { user } = useUserAuth(); const { projectDetails } = useProjectDetails(); useEffect(() => { if (createUpdateCycleModal) return; const timer = setTimeout(() => { setSelectedCycle(undefined); clearTimeout(timer); }, 500); }, [createUpdateCycleModal]); return ( } right={ { const e = new KeyboardEvent("keydown", { key: "q" }); document.dispatchEvent(e); }} > Add Cycle } > setCreateUpdateCycleModal(false)} data={selectedCycle} user={user} /> {projectDetails?.total_cycles === 0 ? (
} onClick={() => { const e = new KeyboardEvent("keydown", { key: "q", }); document.dispatchEvent(e); }} />
) : ( { switch (i) { case 0: return setCycleTab("All"); case 1: return setCycleTab("Active"); case 2: return setCycleTab("Upcoming"); case 3: return setCycleTab("Completed"); case 4: return setCycleTab("Drafts"); default: return setCycleTab("All"); } }} >
{tabsList.map((tab, index) => { if (cyclesView === "gantt_chart" && (tab === "Active" || tab === "Drafts")) return null; return ( `border-b-2 p-4 text-sm font-medium outline-none ${ selected ? "border-custom-primary-100 text-custom-primary-100" : "border-transparent" }` } > {tab} ); })}
{cycleViews.map((view) => { if (cycleTab === "Active") return null; if (view.key === "gantt" && cycleTab === "Drafts") return null; return ( ); })}
{cyclesView !== "gantt_chart" && ( )} {cyclesView !== "gantt_chart" && ( )}
)}
); }; export default ProjectCycles;