import React, { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { Search } from "lucide-react"; import { Combobox, Dialog, Transition } from "@headlessui/react"; // hooks // icons // components // ui import { TOAST_TYPE, setToast } from "@plane/ui"; import { EmptyState } from "@/components/empty-state"; // services // constants import { EmptyStateType } from "@/constants/empty-state"; import { PROJECT_ISSUES_LIST } from "@/constants/fetch-keys"; import { useProject, useProjectState } from "@/hooks/store"; import { IssueService } from "@/services/issue"; type Props = { isOpen: boolean; value?: string | null; onClose: () => void; onSubmit: (issueId: string) => void; }; const issueService = new IssueService(); export const SelectDuplicateInboxIssueModal: React.FC = (props) => { const { isOpen, onClose, onSubmit, value } = props; const [query, setQuery] = useState(""); const router = useRouter(); const { workspaceSlug, projectId, issueId } = router.query; // hooks const { getProjectStates } = useProjectState(); const { getProjectById } = useProject(); const { data: issues } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string) : null, workspaceSlug && projectId ? () => issueService .getIssues(workspaceSlug as string, projectId as string) .then((res) => Object.values(res ?? {}).filter((issue) => issue.id !== issueId)) : null ); const handleClose = () => { onClose(); }; const handleSubmit = (selectedItem: string) => { if (!selectedItem || selectedItem.length === 0) return setToast({ title: "Error", type: TOAST_TYPE.ERROR, }); onSubmit(selectedItem); handleClose(); }; const filteredIssues = (query === "" ? issues : issues?.filter((issue) => issue.name.includes(query))) ?? []; return ( setQuery("")} appear>
{filteredIssues.length > 0 ? (
  • {query === "" && (

    Select issue

    )}
      {filteredIssues.map((issue) => { const stateColor = getProjectStates(issue?.project_id)?.find((state) => state?.id == issue?.state_id) ?.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}
      ); })}
  • ) : (
    )}
    ); };