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 { AssigneesList, Avatar } from "components/ui"; // icons import { UserGroupIcon, MagnifyingGlassIcon, CheckIcon } 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) => ( <> `flex items-center text-xs cursor-pointer border rounded-md shadow-sm duration-200 ${ open ? "outline-none border-theme bg-theme/5 ring-1 ring-theme " : "hover:bg-theme/5 " }` } > {value && value.length > 0 && Array.isArray(value) ? ( {value.length} Assignees ) : ( Assignee )}
setQuery(event.target.value)} placeholder="Search for a person..." displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `${ active ? "bg-gray-200" : "" } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-gray-500` } value={option.value} > {({ selected, active }) => (
p.member.id === option.value)?.member} /> {option.display}
)}
)) ) : (

No assignees found

) ) : (

Loading...

)}
)}
); };