diff --git a/apps/app/components/cycles/sidebar.tsx b/apps/app/components/cycles/sidebar.tsx index c61102fb1..ce61afea6 100644 --- a/apps/app/components/cycles/sidebar.tsx +++ b/apps/app/components/cycles/sidebar.tsx @@ -6,7 +6,7 @@ import Image from "next/image"; import { mutate } from "swr"; // react-hook-form -import { Controller, useForm } from "react-hook-form"; +import { useForm } from "react-hook-form"; import { Popover, Transition } from "@headlessui/react"; import DatePicker from "react-datepicker"; // icons @@ -19,7 +19,7 @@ import { UserIcon, } from "@heroicons/react/24/outline"; // ui -import { CustomSelect, Loader, ProgressBar } from "components/ui"; +import { Loader, ProgressBar } from "components/ui"; // hooks import useToast from "hooks/use-toast"; // services @@ -36,17 +36,22 @@ import { renderDateFormat, renderShortNumericDateFormat } from "helpers/date-tim import { CycleIssueResponse, ICycle, IIssue } from "types"; // fetch-keys import { CYCLE_DETAILS } from "constants/fetch-keys"; -// constants -import { CYCLE_STATUS } from "constants/cycle"; type Props = { issues: IIssue[]; cycle: ICycle | undefined; isOpen: boolean; cycleIssues: CycleIssueResponse[]; + cycleStatus: string; }; -export const CycleDetailsSidebar: React.FC = ({ issues, cycle, isOpen, cycleIssues }) => { +export const CycleDetailsSidebar: React.FC = ({ + issues, + cycle, + isOpen, + cycleIssues, + cycleStatus, +}) => { const [cycleDeleteModal, setCycleDeleteModal] = useState(false); const router = useRouter(); @@ -60,7 +65,6 @@ export const CycleDetailsSidebar: React.FC = ({ issues, cycle, isOpen, cy const defaultValues: Partial = { start_date: new Date().toString(), end_date: new Date().toString(), - status: cycle?.status, }; const groupedIssues = { @@ -72,7 +76,7 @@ export const CycleDetailsSidebar: React.FC = ({ issues, cycle, isOpen, cy ...groupBy(cycleIssues ?? [], "issue_detail.state_detail.group"), }; - const { reset, watch, control } = useForm({ + const { reset } = useForm({ defaultValues, }); @@ -118,32 +122,18 @@ export const CycleDetailsSidebar: React.FC = ({ issues, cycle, isOpen, cy <>
- ( - - - {watch("status")} - - } - value={value} - onChange={(value: any) => { - submitChanges({ status: value }); - }} - > - {CYCLE_STATUS.map((option) => ( - - {option.label} - - ))} - - )} - /> + + + {cycleStatus === "current" + ? "In Progress" + : cycleStatus === "completed" + ? "Completed" + : cycleStatus === "upcoming" + ? "Upcoming" + : "Draft"} +
@@ -289,14 +279,16 @@ export const CycleDetailsSidebar: React.FC = ({ issues, cycle, isOpen, cy
) : (
- {cycle.owned_by?.first_name && cycle.owned_by.first_name !== "" - ? cycle.owned_by.first_name.charAt(0) + {cycle.owned_by && + cycle.owned_by?.first_name && + cycle.owned_by?.first_name !== "" + ? cycle.owned_by?.first_name.charAt(0) : cycle.owned_by?.email.charAt(0)}
))} - {cycle.owned_by.first_name !== "" - ? cycle.owned_by.first_name - : cycle.owned_by.email} + {cycle.owned_by?.first_name !== "" + ? cycle.owned_by?.first_name + : cycle.owned_by?.email}
diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx index 771387877..e4c1a5e94 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/cycles/[cycleId].tsx @@ -34,6 +34,8 @@ import { PROJECT_ISSUES_LIST, PROJECT_DETAILS, CYCLE_DETAILS, + CYCLE_COMPLETE_LIST, + CYCLE_CURRENT_AND_UPCOMING_LIST, } from "constants/fetch-keys"; const SingleCycle: React.FC = (props) => { @@ -78,6 +80,40 @@ const SingleCycle: React.FC = (props) => { : null ); + const { data: currentAndUpcomingCycles } = useSWR( + workspaceSlug && projectId ? CYCLE_CURRENT_AND_UPCOMING_LIST(projectId as string) : null, + workspaceSlug && projectId + ? () => + cycleServices.getCurrentAndUpcomingCycles(workspaceSlug as string, projectId as string) + : null + ); + + const { data: completedCycles } = useSWR( + workspaceSlug && projectId ? CYCLE_COMPLETE_LIST(projectId as string) : null, + workspaceSlug && projectId + ? () => cycleServices.getCompletedCycles(workspaceSlug as string, projectId as string) + : null + ); + + const checkForInProgress = currentAndUpcomingCycles?.current_cycle?.filter( + (c) => c.id === cycleDetails?.id + ); + const checkForUpcoming = currentAndUpcomingCycles?.upcoming_cycle?.filter( + (c) => c.id === cycleDetails?.id + ); + const checkForInCompleted = completedCycles?.completed_cycles?.filter( + (c) => c.id === cycleDetails?.id + ); + + const cycleStatus = + checkForInCompleted && checkForInCompleted.length > 0 + ? "completed" + : checkForInProgress && checkForInProgress.length > 0 + ? "current" + : checkForUpcoming && checkForUpcoming.length > 0 + ? "upcoming" + : "draft"; + const { data: cycleIssues } = useSWR( workspaceSlug && projectId && cycleId ? CYCLE_ISSUES(cycleId as string) : null, workspaceSlug && projectId && cycleId @@ -218,6 +254,7 @@ const SingleCycle: React.FC = (props) => {
)} ( () => import("components/cycles").then((a) => a.CompletedCyclesList), @@ -54,6 +58,13 @@ const ProjectCycles: NextPage = () => { : 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 @@ -112,22 +123,29 @@ const ProjectCycles: NextPage = () => { - `rounded-lg px-6 py-2 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` + `w-1/3 rounded-lg px-6 py-2 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` } > Upcoming - `rounded-lg px-6 py-2 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` + `w-1/3 rounded-lg px-6 py-2 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` } > Completed + + ` w-1/3 rounded-lg px-6 py-2 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` + } + > + Draft + @@ -145,6 +163,14 @@ const ProjectCycles: NextPage = () => { /> + + +