import { Fragment, useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { Combobox } from "@headlessui/react"; import { usePopper } from "react-popper"; import { Check, Search } from "lucide-react"; // hooks import { useApplication, useMember, useUser } from "hooks/store"; // components import { BackgroundButton, BorderButton, TransparentButton } from "components/dropdowns"; // icons import { Avatar } from "@plane/ui"; // helpers import { cn } from "helpers/common.helper"; // types import { MemberDropdownProps } from "./types"; type Props = { projectId: string; } & MemberDropdownProps; export const ProjectMemberDropdown: React.FC = observer((props) => { const { button, buttonClassName, buttonContainerClassName, buttonVariant, className = "", disabled = false, dropdownArrow = false, multiple, onChange, placeholder = "Members", placement, projectId, value, } = props; // states const [query, setQuery] = useState(""); // popper-js refs const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); // popper-js init const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); // store hooks const { router: { workspaceSlug }, } = useApplication(); const { currentUser } = useUser(); const { getUserDetails, project: { getProjectMemberIds, fetchProjectMembers }, } = useMember(); const projectMemberIds = getProjectMemberIds(projectId); const options = projectMemberIds?.map((userId) => { const userDetails = getUserDetails(userId); return { value: userId, query: `${userDetails?.display_name} ${userDetails?.first_name} ${userDetails?.last_name}`, content: (
{currentUser?.id === userId ? "You" : userDetails?.display_name}
), }; }); const filteredOptions = query === "" ? options : options?.filter((o) => o.query.toLowerCase().includes(query.toLowerCase())); const comboboxProps: any = { value, onChange, disabled, }; if (multiple) comboboxProps.multiple = true; useEffect(() => { if (!workspaceSlug) return; if (!projectMemberIds) fetchProjectMembers(workspaceSlug, projectId); }, [fetchProjectMembers, projectId, projectMemberIds, workspaceSlug]); return ( {button ? ( ) : ( )}
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `w-full truncate flex items-center justify-between gap-2 rounded px-1 py-1.5 cursor-pointer select-none ${ active ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); });