import { useState, FC, Fragment } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // headless ui import { Transition, Combobox } from "@headlessui/react"; // services import projectServices from "services/project.service"; // ui import { Avatar } from "components/ui"; // icons import { UserIcon } from "@heroicons/react/24/outline"; // fetch keys import { PROJECT_MEMBERS } from "constants/fetch-keys"; export type IssueAssigneeSelectProps = { projectId: string; value: string[]; onChange: (value: string[]) => void; }; export const IssueAssigneeSelect: FC = ({ projectId, value = [], onChange, }) => { // states const [query, setQuery] = useState(""); const router = useRouter(); const { workspaceSlug } = router.query; // fetching project members const { data: people } = useSWR( workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null, workspaceSlug && projectId ? () => projectServices.projectMembers(workspaceSlug as string, projectId as string) : null ); const options = people?.map((person) => ({ value: person.member.id, display: person.member.first_name && person.member.first_name !== "" ? person.member.first_name : person.member.email, })); const filteredOptions = query === "" ? options : options?.filter((option) => option.display.toLowerCase().includes(query.toLowerCase())); return ( onChange(val)} className="relative flex-shrink-0" multiple > {({ open }: any) => ( <> Assignees {Array.isArray(value) ? value .map((v) => options?.find((option) => option.value === v)?.display) .join(", ") || "Assignees" : options?.find((option) => option.value === value)?.display || "Assignees"} setQuery(event.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `${active ? "bg-indigo-50" : ""} ${ selected ? "bg-indigo-50 font-medium" : "" } flex cursor-pointer select-none items-center gap-2 truncate px-2 py-1 text-gray-900` } value={option.value} > {people && ( <> p.member.id === option.value)?.member} /> {option.display} )} )) ) : (

No assignees found

) ) : (

Loading...

)}
)}
); };