2022-12-13 15:52:44 +00:00
// 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
2022-12-13 15:52:44 +00:00
import useSWR from "swr" ;
2022-12-16 16:20:09 +00:00
// hoc
import withAuth from "lib/hoc/withAuthWrapper" ;
2022-11-19 14:21:26 +00:00
// services
2022-12-12 04:49:52 +00:00
import sprintService from "lib/services/cycles.service" ;
2022-11-19 14:21:26 +00:00
// hooks
import useUser from "lib/hooks/useUser" ;
// layouts
2022-12-13 15:52:44 +00:00
import AppLayout from "layouts/app-layout" ;
2022-11-19 14:21:26 +00:00
// components
2022-12-16 16:20:09 +00:00
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
2022-11-29 14:19:39 +00:00
import { BreadcrumbItem , Breadcrumbs , HeaderButton , Spinner , EmptySpace , EmptySpaceItem } from "ui" ;
2022-11-19 14:21:26 +00:00
// icons
2022-12-16 16:20:09 +00:00
import { ArrowPathIcon , PlusIcon } from "@heroicons/react/24/outline" ;
2022-11-19 14:21:26 +00:00
// types
2022-12-16 16:20:09 +00:00
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 = ( ) = > {
2022-12-16 16:20:09 +00:00
const [ selectedCycle , setSelectedCycle ] = useState < SelectSprintType > ( ) ;
const [ createUpdateCycleModal , setCreateUpdateCycleModal ] = useState ( false ) ;
2022-11-19 14:21:26 +00:00
2022-12-16 16:20:09 +00:00
const { activeWorkspace , activeProject } = useUser ( ) ;
2022-11-19 14:21:26 +00:00
const router = useRouter ( ) ;
const { projectId } = router . query ;
2022-11-29 14:19:39 +00:00
const { data : cycles } = useSWR < ICycle [ ] > (
2022-12-13 15:52:44 +00:00
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 ( ( ) = > {
2022-12-16 16:20:09 +00:00
if ( createUpdateCycleModal ) return ;
2022-11-19 14:21:26 +00:00
const timer = setTimeout ( ( ) = > {
2022-12-16 16:20:09 +00:00
setSelectedCycle ( undefined ) ;
2022-11-19 14:21:26 +00:00
clearTimeout ( timer ) ;
} , 500 ) ;
2022-12-16 16:20:09 +00:00
} , [ createUpdateCycleModal ] ) ;
2022-11-19 14:21:26 +00:00
return (
2022-12-07 23:27:10 +00:00
< AppLayout
2022-11-19 14:21:26 +00:00
meta = { {
title : "Plane - Cycles" ,
} }
2022-12-13 15:52:44 +00:00
breadcrumbs = {
< Breadcrumbs >
< BreadcrumbItem title = "Projects" link = "/projects" / >
< BreadcrumbItem title = { ` ${ activeProject ? . name ? ? "Project" } Cycles ` } / >
< / Breadcrumbs >
}
right = {
2022-12-16 16:20:09 +00:00
< HeaderButton
Icon = { PlusIcon }
label = "Add Cycle"
onClick = { ( ) = > {
const e = new KeyboardEvent ( "keydown" , {
ctrlKey : true ,
key : "q" ,
} ) ;
document . dispatchEvent ( e ) ;
} }
/ >
2022-12-13 15:52:44 +00:00
}
2022-11-19 14:21:26 +00:00
>
2022-12-16 16:20:09 +00:00
< CreateUpdateCycleModal
isOpen = { createUpdateCycleModal }
setIsOpen = { setCreateUpdateCycleModal }
2022-11-19 14:21:26 +00:00
projectId = { projectId as string }
2022-12-16 16:20:09 +00:00
data = { selectedCycle }
2022-12-13 15:52:44 +00:00
/ >
2022-11-29 14:19:39 +00:00
{ cycles ? (
cycles . length > 0 ? (
2022-12-13 15:52:44 +00:00
< div className = "space-y-5" >
2022-12-16 16:20:09 +00:00
< CycleStatsView
cycles = { cycles }
setCreateUpdateCycleModal = { setCreateUpdateCycleModal }
setSelectedCycle = { setSelectedCycle }
/ >
2022-11-24 13:48:18 +00:00
< / div >
2022-11-19 14:21:26 +00:00
) : (
2022-11-24 13:48:18 +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 }
2022-12-16 16:20:09 +00:00
action = { ( ) = > setCreateUpdateCycleModal ( true ) }
2022-11-24 13:48:18 +00:00
/ >
< / EmptySpace >
2022-11-19 14:21:26 +00:00
< / div >
2022-11-24 13:48:18 +00:00
)
) : (
< div className = "w-full h-full flex justify-center items-center" >
< Spinner / >
< / div >
) }
2022-12-07 23:27:10 +00:00
< / AppLayout >
2022-11-19 14:21:26 +00:00
) ;
} ;
2022-12-08 14:59:12 +00:00
export default withAuth ( ProjectSprints ) ;