import { ReactElement } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { observer } from "mobx-react"; // hooks import { useCycle, useProject } from "hooks/store"; import useLocalStorage from "hooks/use-local-storage"; // layouts import { AppLayout } from "layouts/app-layout"; // components import { PageHead } from "components/core"; import { CycleIssuesHeader } from "components/headers"; import { CycleDetailsSidebar } from "components/cycles"; import { CycleLayoutRoot } from "components/issues/issue-layouts"; // ui import { EmptyState } from "components/common"; // assets import emptyCycle from "public/empty-state/cycle.svg"; // types import { NextPageWithLayout } from "lib/types"; const CycleDetailPage: NextPageWithLayout = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId, cycleId } = router.query; // store hooks const { fetchCycleDetails, getCycleById } = useCycle(); const { getProjectById } = useProject(); // hooks const { setValue, storedValue } = useLocalStorage("cycle_sidebar_collapsed", "false"); // fetching cycle details const { error } = useSWR( workspaceSlug && projectId && cycleId ? `CYCLE_DETAILS_${cycleId.toString()}` : null, workspaceSlug && projectId && cycleId ? () => fetchCycleDetails(workspaceSlug.toString(), projectId.toString(), cycleId.toString()) : null ); // derived values const isSidebarCollapsed = storedValue ? (storedValue === "true" ? true : false) : false; const cycle = cycleId ? getCycleById(cycleId.toString()) : undefined; const project = projectId ? getProjectById(projectId.toString()) : undefined; const pageTitle = project?.name && cycle?.name ? `${project?.name} - ${cycle?.name}` : undefined; /** * Toggles the sidebar */ const toggleSidebar = () => setValue(`${!isSidebarCollapsed}`); return ( <> {error ? ( router.push(`/${workspaceSlug}/projects/${projectId}/cycles`), }} /> ) : ( <> {cycleId && !isSidebarCollapsed && ( )} > )} > ); }); CycleDetailPage.getLayout = function getLayout(page: ReactElement) { return ( } withProjectWrapper> {page} ); }; export default CycleDetailPage;