import React, { useEffect, useState } from "react"; // next import { useRouter } from "next/router"; import type { NextPage } from "next"; // swr import useSWR, { mutate } from "swr"; // services import issuesServices from "lib/services/issues.services"; import sprintService from "lib/services/cycles.services"; // hooks import useUser from "lib/hooks/useUser"; // fetching keys import { CYCLE_ISSUES, CYCLE_LIST } from "constants/fetch-keys"; // layouts import AdminLayout from "layouts/AdminLayout"; // components import SprintView from "components/project/cycles/CycleView"; import ConfirmIssueDeletion from "components/project/issues/ConfirmIssueDeletion"; import ConfirmSprintDeletion from "components/project/cycles/ConfirmCycleDeletion"; import CreateUpdateIssuesModal from "components/project/issues/CreateUpdateIssueModal"; import CreateUpdateSprintsModal from "components/project/cycles/CreateUpdateCyclesModal"; // ui import { Spinner } from "ui"; // icons import { PlusIcon } from "@heroicons/react/20/solid"; // types import { IIssue, ICycle, SelectSprintType, SelectIssue } from "types"; import { EmptySpace, EmptySpaceItem } from "ui/EmptySpace"; import { ArrowPathIcon } from "@heroicons/react/24/outline"; import HeaderButton from "ui/HeaderButton"; import { BreadcrumbItem, Breadcrumbs } from "ui/Breadcrumbs"; const ProjectSprints: NextPage = () => { const [isOpen, setIsOpen] = useState(false); const [selectedSprint, setSelectedSprint] = useState(); const [isIssueModalOpen, setIsIssueModalOpen] = useState(false); const [selectedIssues, setSelectedIssues] = useState(); const [deleteIssue, setDeleteIssue] = useState(); const { activeWorkspace, activeProject } = useUser(); const router = useRouter(); const { projectId } = router.query; const { data: sprints } = useSWR( projectId && activeWorkspace ? CYCLE_LIST(projectId as string) : null, activeWorkspace && projectId ? () => sprintService.getCycles(activeWorkspace.slug, projectId as string) : null ); const openIssueModal = ( sprintId: string, issue?: IIssue, actionType: "create" | "edit" | "delete" = "create" ) => { const sprint = sprints?.find((sprint) => sprint.id === sprintId); if (sprint) { setSelectedSprint({ ...sprint, actionType: "create-issue", }); if (issue) setSelectedIssues({ ...issue, actionType }); setIsIssueModalOpen(true); } }; const addIssueToSprint = (sprintId: string, issueId: string) => { if (!activeWorkspace || !projectId) return; issuesServices .addIssueToSprint(activeWorkspace.slug, projectId as string, sprintId, { issue: issueId, }) .then((response) => { console.log(response); mutate(CYCLE_ISSUES(sprintId)); }) .catch((error) => { console.log(error); }); }; useEffect(() => { if (isOpen) return; const timer = setTimeout(() => { setSelectedSprint(undefined); clearTimeout(timer); }, 500); }, [isOpen]); useEffect(() => { if (selectedIssues?.actionType === "delete") { setDeleteIssue(selectedIssues.id); } }, [selectedIssues]); return ( setDeleteIssue(undefined)} isOpen={!!deleteIssue} data={selectedIssues} /> {sprints ? ( sprints.length > 0 ? (

Project Cycle

setIsOpen(true)} />
{sprints.map((sprint) => ( ))}
) : (
Use
Ctrl/Command + Q
{" "} shortcut to create a new cycle } Icon={PlusIcon} action={() => setIsOpen(true)} />
) ) : (
)}
); }; export default ProjectSprints;