plane/apps/app/pages/projects/[projectId]/cycles/index.tsx

124 lines
3.8 KiB
TypeScript
Raw Normal View History

// react
2022-11-19 14:21:26 +00:00
import React, { useEffect, useState } from "react";
// next
import { useRouter } from "next/router";
import type { NextPage } from "next";
// swr
import useSWR from "swr";
// hoc
import withAuth from "lib/hoc/withAuthWrapper";
2022-11-19 14:21:26 +00:00
// services
import sprintService from "lib/services/cycles.service";
2022-11-19 14:21:26 +00:00
// hooks
import useUser from "lib/hooks/useUser";
// layouts
import AppLayout from "layouts/app-layout";
2022-11-19 14:21:26 +00:00
// components
import CreateUpdateCycleModal from "components/project/cycles/create-update-cycle-modal";
2022-12-15 04:17:56 +00:00
import CycleStatsView from "components/project/cycles/stats-view";
2022-11-19 14:21:26 +00:00
// ui
import { BreadcrumbItem, Breadcrumbs, HeaderButton, Spinner, EmptySpace, EmptySpaceItem } from "ui";
2022-11-19 14:21:26 +00:00
// icons
import { ArrowPathIcon, PlusIcon } from "@heroicons/react/24/outline";
2022-11-19 14:21:26 +00:00
// types
import { ICycle, SelectSprintType } from "types";
// fetching keys
import { CYCLE_LIST } from "constants/fetch-keys";
2022-11-19 14:21:26 +00:00
const ProjectSprints: NextPage = () => {
const [selectedCycle, setSelectedCycle] = useState<SelectSprintType>();
const [createUpdateCycleModal, setCreateUpdateCycleModal] = useState(false);
2022-11-19 14:21:26 +00:00
const { activeWorkspace, activeProject } = useUser();
2022-11-19 14:21:26 +00:00
const router = useRouter();
const { projectId } = router.query;
const { data: cycles } = useSWR<ICycle[]>(
activeWorkspace && projectId ? CYCLE_LIST(projectId as string) : null,
2022-11-19 14:21:26 +00:00
activeWorkspace && projectId
? () => sprintService.getCycles(activeWorkspace.slug, projectId as string)
: null
);
useEffect(() => {
if (createUpdateCycleModal) return;
2022-11-19 14:21:26 +00:00
const timer = setTimeout(() => {
setSelectedCycle(undefined);
2022-11-19 14:21:26 +00:00
clearTimeout(timer);
}, 500);
}, [createUpdateCycleModal]);
2022-11-19 14:21:26 +00:00
return (
<AppLayout
2022-11-19 14:21:26 +00:00
meta={{
title: "Plane - Cycles",
}}
breadcrumbs={
<Breadcrumbs>
<BreadcrumbItem title="Projects" link="/projects" />
<BreadcrumbItem title={`${activeProject?.name ?? "Project"} Cycles`} />
</Breadcrumbs>
}
right={
<HeaderButton
Icon={PlusIcon}
label="Add Cycle"
onClick={() => {
const e = new KeyboardEvent("keydown", {
ctrlKey: true,
key: "q",
});
document.dispatchEvent(e);
}}
/>
}
2022-11-19 14:21:26 +00:00
>
<CreateUpdateCycleModal
isOpen={createUpdateCycleModal}
setIsOpen={setCreateUpdateCycleModal}
2022-11-19 14:21:26 +00:00
projectId={projectId as string}
data={selectedCycle}
/>
{cycles ? (
cycles.length > 0 ? (
<div className="space-y-5">
<CycleStatsView
cycles={cycles}
setCreateUpdateCycleModal={setCreateUpdateCycleModal}
setSelectedCycle={setSelectedCycle}
/>
</div>
2022-11-19 14:21:26 +00:00
) : (
<div className="w-full h-full flex flex-col justify-center items-center px-4">
<EmptySpace
title="You don't have any cycle yet."
description="A cycle is a fixed time period where a team commits to a set number of issues from their backlog. Cycles are usually one, two, or four weeks long."
Icon={ArrowPathIcon}
>
<EmptySpaceItem
title="Create a new cycle"
description={
<span>
Use <pre className="inline bg-gray-100 px-2 py-1 rounded">Ctrl/Command + Q</pre>{" "}
shortcut to create a new cycle
</span>
}
Icon={PlusIcon}
action={() => setCreateUpdateCycleModal(true)}
/>
</EmptySpace>
2022-11-19 14:21:26 +00:00
</div>
)
) : (
<div className="w-full h-full flex justify-center items-center">
<Spinner />
</div>
)}
</AppLayout>
2022-11-19 14:21:26 +00:00
);
};
export default withAuth(ProjectSprints);