import { Fragment, useState } from "react"; import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; import { usePopper } from "react-popper"; import { Combobox } from "@headlessui/react"; import { Check, ChevronDown, Search, User2 } from "lucide-react"; // ui import { Avatar, AvatarGroup, Tooltip } from "@plane/ui"; // types import { Placement } from "@popperjs/core"; export interface IIssuePropertyAssignee { projectId: string | null; value: string[] | string; onChange: (data: string[]) => void; disabled?: boolean; hideDropdownArrow?: boolean; className?: string; buttonClassName?: string; optionsClassName?: string; placement?: Placement; multiple?: true; noLabelBorder?: boolean; } export const IssuePropertyAssignee: React.FC = observer((props) => { const { projectId, value, onChange, disabled = false, hideDropdownArrow = false, className, buttonClassName, optionsClassName, placement, multiple = false, noLabelBorder = false, } = props; // store const { workspace: workspaceStore, project: projectStore, workspaceMember: { workspaceMembers, fetchWorkspaceMembers }, } = useMobxStore(); const workspaceSlug = workspaceStore?.workspaceSlug; // states const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const [isLoading, setIsLoading] = useState(false); // const fetchProjectMembers = () => { // setIsLoading(true); // if (workspaceSlug && projectId) // workspaceSlug && // projectId && // projectStore.fetchProjectMembers(workspaceSlug, projectId).then(() => setIsLoading(false)); // }; const getWorkspaceMembers = () => { setIsLoading(true); if (workspaceSlug) workspaceSlug && fetchWorkspaceMembers(workspaceSlug).then(() => setIsLoading(false)); }; const options = (workspaceMembers ?? [])?.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 getTooltipContent = (): string => { if (!value || value.length === 0) return "No Assignee"; // if multiple assignees if (Array.isArray(value)) { const assignees = workspaceMembers?.filter((m) => value.includes(m.member.id)); if (!assignees || assignees.length === 0) return "No Assignee"; // if only one assignee in list if (assignees.length === 1) { return "1 assignee"; } else return `${assignees.length} assignees`; } // if single assignee const assignee = workspaceMembers?.find((m) => m.member.id === value)?.member; if (!assignee) return "No Assignee"; // if assignee not null & not list return "1 assignee"; }; const label = (
{value && value.length > 0 && Array.isArray(value) ? ( {value.map((assigneeId) => { const member = workspaceMembers?.find((m) => m.member.id === assigneeId)?.member; if (!member) return null; return ; })} ) : ( )}
); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const comboboxProps: any = { value, onChange, disabled }; if (multiple) comboboxProps.multiple = true; return (
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{isLoading ? (

Loading...

) : 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

)}
); });