import React, { useState, useRef } from "react"; import { inject, observer } from "mobx-react"; import { withRouter } from "react-router"; import { useTranslation } from "react-i18next"; import Avatar from "@docspace/components/avatar"; import Text from "@docspace/components/text"; import ContextMenuButton from "@docspace/components/context-menu-button"; import ContextMenu from "@docspace/components/context-menu"; import { isTablet as isTabletUtils } from "@docspace/components/utils/device"; import { isTablet, isMobileOnly } from "react-device-detect"; import { StyledArticleProfile, StyledUserName, StyledProfileWrapper, } from "../styled-article"; const ArticleProfile = (props) => { const { user, showText, getUserRole, getActions, onProfileClick } = props; const { t } = useTranslation("Common"); const [isOpen, setIsOpen] = useState(false); const ref = useRef(null); const menuRef = useRef(null); const isTabletView = (isTabletUtils() || isTablet) && !isMobileOnly; const avatarSize = isTabletView ? "min" : "base"; const userRole = getUserRole(user); const toggle = (e, isOpen) => { isOpen ? menuRef.current.show(e) : menuRef.current.hide(e); setIsOpen(isOpen); }; const onAvatarClick = (e) => { if (isTabletView && !showText) { toggle(e, !isOpen); } else { onProfileClick(); } }; const onHide = () => { setIsOpen(false); }; const model = getActions(t); const username = user.displayName.split(" "); return (
{(!isTabletView || showText) && ( <> {username[0]}   {username[1]} getActions(t)} isDisabled={false} usePortal={true} /> )}
); }; export default withRouter( inject(({ auth, profileActionsStore }) => { const { getActions, getUserRole, onProfileClick } = profileActionsStore; return { onProfileClick, user: auth.userStore.user, getUserRole, getActions, }; })(observer(ArticleProfile)) );