"use client"; import React, { useEffect, useState } from "react"; import { useParams } from "next/navigation"; import { Search } from "lucide-react"; import { Combobox, Dialog, Transition } from "@headlessui/react"; // icons // components // types import { ISearchIssueResponse } from "@plane/types"; // ui import { Loader, TOAST_TYPE, setToast } from "@plane/ui"; import { EmptyState } from "@/components/empty-state"; // constants import { EmptyStateType } from "@/constants/empty-state"; // hooks import { useProject } from "@/hooks/store"; import useDebounce from "@/hooks/use-debounce"; // services import { ProjectService } from "@/services/project"; type Props = { isOpen: boolean; value?: string | null; onClose: () => void; onSubmit: (issueId: string) => void; }; const projectService = new ProjectService(); export const SelectDuplicateInboxIssueModal: React.FC = (props) => { const { isOpen, onClose, onSubmit, value } = props; const [query, setQuery] = useState(""); const { workspaceSlug, projectId, issueId } = useParams(); // hooks const { getProjectById } = useProject(); const [issues, setIssues] = useState([]); const [isSearching, setIsSearching] = useState(false); const debouncedSearchTerm: string = useDebounce(query, 500); useEffect(() => { if (!isOpen || !workspaceSlug || !projectId) return; setIsSearching(true); projectService .projectIssuesSearch(workspaceSlug.toString(), projectId.toString(), { search: debouncedSearchTerm, workspace_search: false, }) .then((res: ISearchIssueResponse[]) => setIssues(res)) .finally(() => setIsSearching(false)); }, [debouncedSearchTerm, isOpen, projectId, workspaceSlug]); const filteredIssues = issues.filter((issue) => issue.id !== issueId); const handleClose = () => { onClose(); }; const handleSubmit = (selectedItem: string) => { if (!selectedItem || selectedItem.length === 0) return setToast({ title: "Error", type: TOAST_TYPE.ERROR, }); onSubmit(selectedItem); handleClose(); }; const issueList = filteredIssues.length > 0 ? (
  • {query === "" &&

    Select issue

    }
      {filteredIssues.map((issue) => { const stateColor = issue.state__color || ""; return ( `flex w-full cursor-pointer select-none items-center gap-2 rounded-md px-3 py-2 text-custom-text-200 ${ active || selected ? "bg-custom-background-80 text-custom-text-100" : "" } ` } >
      {getProjectById(issue?.project_id)?.identifier}-{issue.sequence_id} {issue.name}
      ); })}
  • ) : (
    ); return ( setQuery("")} appear>
    {isSearching ? ( ) : ( <>{issueList} )}
    ); };