import React, { useState } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import type { FieldError } from "react-hook-form"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // popper js import { usePopper } from "react-popper"; // ui import { Combobox } from "@headlessui/react"; // helpers import { renderEmoji } from "helpers/emoji.helper"; // icons import { Check, Clipboard, Search } from "lucide-react"; export interface IssueProjectSelectProps { value: string; onChange: (value: string) => void; error?: FieldError; } export const IssueProjectSelect: React.FC = observer((props) => { const { value, onChange } = props; const [query, setQuery] = useState(""); const router = useRouter(); const { workspaceSlug } = router.query; const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "bottom-start", }); const { project: projectStore } = useMobxStore(); const projects = workspaceSlug ? projectStore.projects[workspaceSlug.toString()] : undefined; const selectedProject = projects?.find((i) => i.id === value); const options = projects?.map((project) => ({ value: project.id, query: project.name, content: (
{project.emoji ? renderEmoji(project.emoji) : project.icon_prop ? renderEmoji(project.icon_prop) : null} {project.name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const label = selectedProject ? (
{selectedProject.emoji ? renderEmoji(selectedProject.emoji) : selectedProject.icon_prop ? renderEmoji(selectedProject.icon_prop) : null}
{selectedProject.identifier}
) : ( <> Select Project ); return ( onChange(val)}>
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `flex items-center justify-between gap-2 cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active && !selected ? "bg-custom-background-80" : "" } w-full truncate ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); });