import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; import dynamic from "next/dynamic"; import useSWR from "swr"; // headless ui import { Tab } from "@headlessui/react"; // services import cycleService from "services/cycles.service"; import projectService from "services/project.service"; // layouts import { ProjectAuthorizationWrapper } from "layouts/auth-layout"; // components import { CompletedCyclesListProps, CreateUpdateCycleModal, CyclesList } from "components/cycles"; // ui import { Loader, PrimaryButton } from "components/ui"; import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; // icons import { PlusIcon } from "@heroicons/react/24/outline"; // types import { SelectCycleType } from "types"; import type { NextPage } from "next"; // fetch-keys import { CYCLE_CURRENT_AND_UPCOMING_LIST, CYCLE_DRAFT_LIST, PROJECT_DETAILS, } from "constants/fetch-keys"; const CompletedCyclesList = dynamic( () => import("components/cycles").then((a) => a.CompletedCyclesList), { ssr: false, loading: () => ( ), } ); const ProjectCycles: NextPage = () => { const [selectedCycle, setSelectedCycle] = useState(); const [createUpdateCycleModal, setCreateUpdateCycleModal] = useState(false); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: activeProject } = useSWR( workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, workspaceSlug && projectId ? () => projectService.getProject(workspaceSlug as string, projectId as string) : null ); const { data: draftCycles } = useSWR( workspaceSlug && projectId ? CYCLE_DRAFT_LIST(projectId as string) : null, workspaceSlug && projectId ? () => cycleService.getDraftCycles(workspaceSlug as string, projectId as string) : null ); const { data: currentAndUpcomingCycles } = useSWR( workspaceSlug && projectId ? CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string) : null, workspaceSlug && projectId ? () => cycleService.getCurrentAndUpcomingCycles(workspaceSlug as string, projectId as string) : null ); 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} />
{currentAndUpcomingCycles && currentAndUpcomingCycles.current_cycle.length > 0 && (

Current Cycle

)}

Other Cycles

`rounded-3xl border px-5 py-1.5 text-sm outline-none sm:px-7 sm:py-2 sm:text-base ${ selected ? "border-theme bg-theme text-white" : "border-gray-300 bg-white hover:bg-hover-gray" }` } > Upcoming `rounded-3xl border px-5 py-1.5 text-sm outline-none sm:px-7 sm:py-2 sm:text-base ${ selected ? "border-theme bg-theme text-white" : "border-gray-300 bg-white hover:bg-hover-gray" }` } > Completed `rounded-3xl border px-5 py-1.5 text-sm outline-none sm:px-7 sm:py-2 sm:text-base ${ selected ? "border-theme bg-theme text-white" : "border-gray-300 bg-white hover:bg-hover-gray" }` } > Drafts
); }; export default ProjectCycles;