import React, { useState } from "react"; // swr import useSWR from "swr"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // react hook form import { useForm, Controller, UseFormWatch } from "react-hook-form"; // services import stateServices from "lib/services/state.service"; import issuesServices from "lib/services/issues.service"; import workspaceService from "lib/services/workspace.service"; // hooks import useUser from "lib/hooks/useUser"; import useToast from "lib/hooks/useToast"; // components import IssuesListModal from "components/project/issues/IssuesListModal"; // fetching keys import { STATE_LIST, WORKSPACE_MEMBERS, PROJECT_ISSUE_LABELS } from "constants/fetch-keys"; // commons import { classNames, copyTextToClipboard } from "constants/common"; import { PRIORITIES } from "constants/"; // ui import { Input, Button, Spinner } from "ui"; import { Popover } from "@headlessui/react"; // icons import { UserIcon, TagIcon, UserGroupIcon, ChevronDownIcon, Squares2X2Icon, ChartBarIcon, ClipboardDocumentIcon, LinkIcon, ArrowPathIcon, CalendarDaysIcon, TrashIcon, PlusIcon, XMarkIcon, } from "@heroicons/react/24/outline"; // types import type { Control } from "react-hook-form"; import type { IIssue, IIssueLabels, IssueResponse, IState, NestedKeyOf } from "types"; import { TwitterPicker } from "react-color"; import { positionEditorElement } from "components/lexical/helpers/editor"; import SelectState from "./select-state"; import SelectPriority from "./select-priority"; import SelectParent from "./select-parent"; import SelectCycle from "./select-cycle"; import SelectAssignee from "./select-assignee"; type Props = { control: Control; submitChanges: (formData: Partial) => void; issueDetail: IIssue | undefined; watch: UseFormWatch; setDeleteIssueModal: React.Dispatch>; }; const defaultValues: Partial = { name: "", colour: "#ff0000", }; const IssueDetailSidebar: React.FC = ({ control, submitChanges, issueDetail, watch: watchIssue, setDeleteIssueModal, }) => { const [isBlockerModalOpen, setIsBlockerModalOpen] = useState(false); const [isBlockedModalOpen, setIsBlockedModalOpen] = useState(false); const [createLabelForm, setCreateLabelForm] = useState(false); const { activeWorkspace, activeProject, cycles, issues } = useUser(); const { setToastAlert } = useToast(); const { data: issueLabels, mutate: issueLabelMutate } = useSWR( activeProject && activeWorkspace ? PROJECT_ISSUE_LABELS(activeProject.id) : null, activeProject && activeWorkspace ? () => issuesServices.getIssueLabels(activeWorkspace.slug, activeProject.id) : null ); const { register, handleSubmit, formState: { isSubmitting }, reset, watch, control: controlLabel, } = useForm({ defaultValues, }); const handleNewLabel = (formData: any) => { if (!activeWorkspace || !activeProject || isSubmitting) return; issuesServices .createIssueLabel(activeWorkspace.slug, activeProject.id, formData) .then((res) => { console.log(res); reset(defaultValues); issueLabelMutate((prevData) => [...(prevData ?? []), res], false); }); }; const sidebarSections: Array< Array<{ label: string; name: NestedKeyOf; canSelectMultipleOptions: boolean; icon: (props: any) => JSX.Element; options?: Array<{ label: string; value: any; color?: string }>; modal: boolean; issuesList?: Array; isOpen?: boolean; setIsOpen?: (arg: boolean) => void; }> > = [ [ // { // label: "Blocker", // name: "blockers_list", // canSelectMultipleOptions: true, // icon: UserIcon, // issuesList: issues?.results.filter((i) => i.id !== issueDetail?.id) ?? [], // modal: true, // isOpen: isBlockerModalOpen, // setIsOpen: setIsBlockerModalOpen, // }, // { // label: "Blocked", // name: "blocked_list", // canSelectMultipleOptions: true, // icon: UserIcon, // issuesList: issues?.results.filter((i) => i.id !== issueDetail?.id) ?? [], // modal: true, // isOpen: isBlockedModalOpen, // setIsOpen: setIsBlockedModalOpen, // }, ], ]; const handleCycleChange = (cycleId: string) => { if (activeWorkspace && activeProject && issueDetail) issuesServices.addIssueToCycle(activeWorkspace.slug, activeProject.id, cycleId, { issue: issueDetail.id, }); }; return ( <>

{activeProject?.identifier}-{issueDetail?.sequence_id}

i.id !== issueDetail?.id && i.id !== issueDetail?.parent && i.parent !== issueDetail?.id ) ?? [] } customDisplay={ issueDetail?.parent_detail ? ( ) : (
No parent selected
) } watchIssue={watchIssue} />

Due date

( { submitChanges({ target_date: e.target.value }); onChange(e.target.value); }} className="hover:bg-gray-100 border rounded-md shadow-sm px-2 py-1 cursor-pointer focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 text-xs duration-300 w-full" /> )} />
{/* {sidebarSections.map((section, index) => (
{section.map((item) => (

{item.label}

( <> item.setIsOpen && item.setIsOpen(false)} onChange={(val) => { console.log(val); submitChanges({ [item.name]: val }); onChange(val); }} issues={item?.issuesList ?? []} title={`Select ${item.label}`} multiple={item.canSelectMultipleOptions} value={value} customDisplay={ issueDetail?.parent_detail ? ( ) : (
No parent selected
) } /> )} />
))}
))} */}

Label

{issueDetail?.label_details.map((label) => ( { const updatedLabels = issueDetail?.labels.filter((l) => l !== label.id); submitChanges({ labels_list: updatedLabels, }); }} > {label.name} ))} ( submitChanges({ labels_list: val })} className="flex-shrink-0" > {({ open }) => ( <> Label
Select Label
{issueLabels ? ( issueLabels.length > 0 ? ( issueLabels.map((label: IIssueLabels) => ( `${ active || selected ? "text-white bg-theme" : "text-gray-900" } flex items-center gap-2 cursor-pointer select-none relative p-2 rounded-md truncate` } value={label.id} > {label.name} )) ) : (
No labels found
) ) : ( )}
)}
)} />
{createLabelForm && (
{({ open }) => ( <> {watch("colour") && watch("colour") !== "" && ( )} ( onChange(value.hex)} /> )} /> )}
)}
); }; export default IssueDetailSidebar;