import { Fragment, useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { Combobox } from "@headlessui/react"; import { ChevronDown } from "lucide-react"; // hooks import { useMember } from "hooks/store"; import { useDropdownKeyDown } from "hooks/use-dropdown-key-down"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; // components import { ButtonAvatars } from "./avatar"; import { DropdownButton } from "../buttons"; // helpers import { cn } from "helpers/common.helper"; // types import { MemberDropdownProps } from "./types"; // constants import { BUTTON_VARIANTS_WITH_TEXT } from "../constants"; import { MemberOptions } from "./member-options"; type Props = { projectId?: string; onClose?: () => void; } & MemberDropdownProps; export const MemberDropdown: React.FC = observer((props) => { const { button, buttonClassName, buttonContainerClassName, buttonVariant, className = "", disabled = false, dropdownArrow = false, dropdownArrowClassName = "", hideIcon = false, multiple, onChange, onClose, placeholder = "Members", placement, projectId, showTooltip = false, tabIndex, value, } = props; // states const [isOpen, setIsOpen] = useState(false); // refs const dropdownRef = useRef(null); // popper-js refs const [referenceElement, setReferenceElement] = useState(null); const { getUserDetails } = useMember(); const comboboxProps: any = { value, onChange, disabled, }; if (multiple) comboboxProps.multiple = true; const handleClose = () => { if (!isOpen) return; setIsOpen(false); onClose && onClose(); }; const toggleDropdown = () => { setIsOpen((prevIsOpen) => !prevIsOpen); if (isOpen) onClose && onClose(); }; const dropdownOnChange = (val: string & string[]) => { onChange(val); if (!multiple) handleClose(); }; const handleKeyDown = useDropdownKeyDown(toggleDropdown, handleClose); const handleOnClick = (e: React.MouseEvent) => { e.stopPropagation(); e.preventDefault(); toggleDropdown(); }; useOutsideClickDetector(dropdownRef, handleClose); return ( {button ? ( ) : ( )} {isOpen && ( )} ); });