import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { Combobox, Dialog, Transition } from "@headlessui/react"; // hooks import { useProject, useProjectState } from "hooks/store"; // icons import { Search } from "lucide-react"; // components import { EmptyState } from "components/empty-state"; // ui import { Button, TOAST_TYPE, setToast } from "@plane/ui"; // services import { IssueService } from "services/issue"; // constants import { PROJECT_ISSUES_LIST } from "constants/fetch-keys"; import { EmptyStateType } from "constants/empty-state"; 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 [selectedItem, setSelectedItem] = 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 ); useEffect(() => { if (!value) { setSelectedItem(""); return; } else setSelectedItem(value); }, [value]); const handleClose = () => { onClose(); }; const handleSubmit = () => { 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>
{ setSelectedItem(value); }} >
{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}
      ); })}
  • ) : (
    )}
    {filteredIssues.length > 0 && (
    )}
    ); };