import React, { useState } from "react"; import { useRouter } from "next/router"; // react-popper import { usePopper } from "react-popper"; // hooks import useProjectMembers from "hooks/use-project-members"; import useWorkspaceMembers from "hooks/use-workspace-members"; // headless ui import { Combobox } from "@headlessui/react"; // components import { AssigneesList, Avatar, Tooltip } from "components/ui"; // icons import { Check, ChevronDown, Search, User2 } from "lucide-react"; // types import { IUser } from "types"; import { Placement } from "@popperjs/core"; type Props = { value: string | string[]; projectId: string; onChange: (data: any) => void; membersDetails: IUser[]; renderWorkspaceMembers?: boolean; className?: string; buttonClassName?: string; optionsClassName?: string; placement?: Placement; hideDropdownArrow?: boolean; disabled?: boolean; }; export const MembersSelect: React.FC = ({ value, projectId, onChange, membersDetails, renderWorkspaceMembers = false, className = "", buttonClassName = "", optionsClassName = "", placement, hideDropdownArrow = false, disabled = false, }) => { const [query, setQuery] = useState(""); const [fetchStates, setFetchStates] = useState(false); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const router = useRouter(); const { workspaceSlug } = router.query; const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", }); const { members } = useProjectMembers(workspaceSlug?.toString(), projectId, fetchStates && !renderWorkspaceMembers); const { workspaceMembers } = useWorkspaceMembers( workspaceSlug?.toString() ?? "", fetchStates && renderWorkspaceMembers ); const membersOptions = renderWorkspaceMembers ? workspaceMembers : members; const options = membersOptions?.map((member) => ({ value: member.member.id, query: member.member.display_name, content: (
{member.member.display_name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const label = ( 0 ? membersDetails.map((assignee) => assignee?.display_name).join(", ") : "No Assignee" } position="top" >
{value && value.length > 0 && Array.isArray(value) ? ( ) : ( )}
); return ( {({ open }: { open: boolean }) => { if (open) setFetchStates(true); return ( <>
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" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); }}
); };