From ebf294af5599e49ba918380e7bb6669e7b1c7b9e Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Mon, 13 Feb 2023 10:33:02 +0530 Subject: [PATCH] feat : cycle sidebar revamp (#271) * feat: range date picker added * feat: cycle status ui improved --- .../cycles/cycle-detail-sidebar/index.tsx | 171 ++++++++++-------- apps/app/components/project/cycles/index.ts | 1 - .../project/cycles/sidebar-select/index.ts | 1 - .../cycles/sidebar-select/select-status.tsx | 69 ------- 4 files changed, 99 insertions(+), 143 deletions(-) delete mode 100644 apps/app/components/project/cycles/sidebar-select/index.ts delete mode 100644 apps/app/components/project/cycles/sidebar-select/select-status.tsx diff --git a/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx b/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx index cdbac8b17..e1aa46692 100644 --- a/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx +++ b/apps/app/components/project/cycles/cycle-detail-sidebar/index.tsx @@ -1,4 +1,4 @@ -import { useEffect } from "react"; +import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; import Image from "next/image"; @@ -10,11 +10,18 @@ import { Controller, useForm } from "react-hook-form"; // react-circular-progressbar import { CircularProgressbar } from "react-circular-progressbar"; import "react-circular-progressbar/dist/styles.css"; +import { Popover, Transition } from "@headlessui/react"; +import DatePicker from "react-datepicker"; // icons -import { CalendarDaysIcon, ChartPieIcon, LinkIcon, UserIcon } from "@heroicons/react/24/outline"; -import { CycleSidebarStatusSelect } from "components/project/cycles"; +import { + CalendarDaysIcon, + ChartPieIcon, + LinkIcon, + Squares2X2Icon, + UserIcon, +} from "@heroicons/react/24/outline"; // ui -import { Loader, CustomDatePicker } from "components/ui"; +import { CustomSelect, Loader } from "components/ui"; // hooks import useToast from "hooks/use-toast"; // services @@ -24,12 +31,13 @@ import { SidebarProgressStats } from "components/core"; // helpers import { copyTextToClipboard } from "helpers/string.helper"; import { groupBy } from "helpers/array.helper"; -import { renderShortNumericDateFormat } from "helpers/date-time.helper"; +import { renderDateFormat, renderShortNumericDateFormat } from "helpers/date-time.helper"; // types import { CycleIssueResponse, ICycle, IIssue } from "types"; // fetch-keys import { CYCLE_DETAILS } from "constants/fetch-keys"; import ProgressChart from "components/core/sidebar/progress-chart"; +import { CYCLE_STATUS } from "constants/cycle"; type Props = { issues: IIssue[]; @@ -42,6 +50,9 @@ const CycleDetailSidebar: React.FC = ({ issues, cycle, isOpen, cycleIssue const router = useRouter(); const { workspaceSlug, projectId, cycleId } = router.query; + const [startDateRange, setStartDateRange] = useState(new Date()); + const [endDateRange, setEndDateRange] = useState(null); + const { setToastAlert } = useToast(); const defaultValues: Partial = { @@ -98,21 +109,90 @@ const CycleDetailSidebar: React.FC = ({ issues, cycle, isOpen, cycleIssue > {cycle ? ( <> -
-
- {cycle.status} -
-
- - {renderShortNumericDateFormat(`${cycle.start_date}`) - ? renderShortNumericDateFormat(`${cycle.start_date}`) - : "N/A"}{" "} - -{" "} - {renderShortNumericDateFormat(`${cycle.end_date}`) - ? renderShortNumericDateFormat(`${cycle.end_date}`) - : "N/A"} - +
+
+ ( + + + {watch("status")} + + } + value={value} + onChange={(value: any) => { + submitChanges({ status: value }); + }} + > + {CYCLE_STATUS.map((option) => ( + + {option.label} + + ))} + + )} + />
+ + {({ open }) => ( + <> + + + + {renderShortNumericDateFormat(`${cycle.start_date}`) + ? renderShortNumericDateFormat(`${cycle.start_date}`) + : "N/A"}{" "} + -{" "} + {renderShortNumericDateFormat(`${cycle.end_date}`) + ? renderShortNumericDateFormat(`${cycle.end_date}`) + : "N/A"} + + + + + + { + const [start, end] = dates; + submitChanges({ + start_date: renderDateFormat(start), + end_date: renderDateFormat(end), + }); + if (setStartDateRange) { + setStartDateRange(start); + } + if (setEndDateRange) { + setEndDateRange(end); + } + }} + startDate={startDateRange} + endDate={endDateRange} + selectsRange + inline + /> + + + + )} +

{cycle.name}

@@ -192,59 +272,6 @@ const CycleDetailSidebar: React.FC = ({ issues, cycle, isOpen, cycleIssue
-
-
-
- -

Start date

-
-
- ( - - submitChanges({ - start_date: val, - }) - } - isClearable={false} - /> - )} - /> -
-
-
-
- -

End date

-
-
- ( - - submitChanges({ - end_date: val, - }) - } - isClearable={false} - /> - )} - /> -
-
- -
diff --git a/apps/app/components/project/cycles/index.ts b/apps/app/components/project/cycles/index.ts index 9c6e55594..d330ba698 100644 --- a/apps/app/components/project/cycles/index.ts +++ b/apps/app/components/project/cycles/index.ts @@ -1,3 +1,2 @@ -export * from "./sidebar-select"; export * from "./stats-view"; export * from "./cycle-detail-sidebar"; \ No newline at end of file diff --git a/apps/app/components/project/cycles/sidebar-select/index.ts b/apps/app/components/project/cycles/sidebar-select/index.ts deleted file mode 100644 index efa8c553e..000000000 --- a/apps/app/components/project/cycles/sidebar-select/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./select-status"; \ No newline at end of file diff --git a/apps/app/components/project/cycles/sidebar-select/select-status.tsx b/apps/app/components/project/cycles/sidebar-select/select-status.tsx deleted file mode 100644 index 0c53083bd..000000000 --- a/apps/app/components/project/cycles/sidebar-select/select-status.tsx +++ /dev/null @@ -1,69 +0,0 @@ -// react -import React from "react"; -// react-hook-form -import { Control, Controller, UseFormWatch } from "react-hook-form"; -// icons -import { Squares2X2Icon } from "@heroicons/react/24/outline"; -// ui -import { CustomSelect } from "components/ui"; -// types -import { ICycle } from "types"; -// common -// constants -import { CYCLE_STATUS } from "constants/cycle"; - -type Props = { - control: Control, any>; - submitChanges: (formData: Partial) => void; - watch: UseFormWatch>; -}; - -export const CycleSidebarStatusSelect: React.FC = ({ control, submitChanges, watch }) => ( -
-
- -

Status

-
-
- ( - - option.value === value)?.color, - }} - /> - {watch("status")} - - } - value={value} - onChange={(value: any) => { - submitChanges({ status: value }); - }} - > - {CYCLE_STATUS.map((option) => ( - - <> - - {option.label} - - - ))} - - )} - /> -
-
-);