// react 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"; // services import issuesServices from "lib/services/issues.service"; // hooks import useUser from "lib/hooks/useUser"; // icons import { RectangleStackIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; // commons import { classNames } from "constants/common"; // types import { IIssue, IssueResponse } from "types"; // constants import { PROJECT_ISSUES_LIST } from "constants/fetch-keys"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; parent: IIssue | undefined; }; type FormInput = { issue_ids: string[]; cycleId: string; }; const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parent }) => { 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 { formState: { errors, isSubmitting }, reset, } = useForm(); const handleCommandPaletteClose = () => { setIsOpen(false); setQuery(""); }; const addAsSubIssue = (issueId: string) => { if (activeWorkspace && activeProject) { issuesServices .patchIssue(activeWorkspace.slug, activeProject.id, issueId, { parent: parent?.id }) .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>
{filteredIssues.length > 0 && ( <>
  • {query === "" && (

    Issues

    )}
      {filteredIssues.map((issue) => { if ( (issue.parent === "" || issue.parent === null) && // issue does not have any other parent issue.id !== parent?.id && // issue is not itself issue.id !== parent?.parent // issue is not it's parent ) 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;