import React, { useState } from "react"; // swr import { mutate } from "swr"; // react hook form import { useForm } from "react-hook-form"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; // hooks import useUser from "lib/hooks/useUser"; // icons import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; import { FolderIcon } from "@heroicons/react/24/outline"; // commons import { classNames } from "constants/common"; // types import { IIssue, IssueResponse } from "types"; import { Button } from "ui"; import { PROJECT_ISSUES_DETAILS, PROJECT_ISSUES_LIST } from "constants/fetch-keys"; import issuesServices from "lib/services/issues.services"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; parentId: string; }; type FormInput = { issue_ids: string[]; cycleId: string; }; const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parentId }) => { const [query, setQuery] = useState(""); const { activeWorkspace, activeProject, issues } = useUser(); const filteredIssues: IIssue[] = query === "" ? issues?.results ?? [] : issues?.results.filter((issue) => issue.name.toLowerCase().includes(query.toLowerCase())) ?? []; const { register, formState: { errors, isSubmitting }, handleSubmit, control, reset, setError, } = useForm(); const handleCommandPaletteClose = () => { setIsOpen(false); setQuery(""); reset(); }; const addAsSubIssue = (issueId: string) => { if (activeWorkspace && activeProject) { issuesServices .patchIssue(activeWorkspace.slug, activeProject.id, issueId, { parent: parentId }) .then((res) => { mutate( PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id), (prevData) => ({ ...(prevData as IssueResponse), results: (prevData?.results ?? []).map((p) => p.id === issueId ? { ...p, ...res } : p ), }), false ); }) .catch((e) => { console.log(e); }); } }; return ( <> setQuery("")} appear>
{ // const { url, onClick } = item; // if (url) router.push(url); // else if (onClick) onClick(); // handleCommandPaletteClose(); // }} >
{filteredIssues.length > 0 && ( <>
  • {query === "" && (

    Issues

    )}
      {filteredIssues.map((issue) => { if (issue.parent === "" || issue.parent === null) return ( classNames( "flex items-center gap-2 cursor-pointer select-none rounded-md px-3 py-2", active ? "bg-gray-900 bg-opacity-5 text-gray-900" : "" ) } onClick={() => { addAsSubIssue(issue.id); setIsOpen(false); }} > {issue.name} ); })}
  • )}
    {query !== "" && filteredIssues.length === 0 && (
    )}
    ); }; export default AddAsSubIssue;