2022-07-19 13:12:46 +00:00
|
|
|
import React, { useState, useRef } from "react";
|
2022-07-11 13:18:35 +00:00
|
|
|
import { inject, observer } from "mobx-react";
|
2022-07-11 20:10:44 +00:00
|
|
|
import { withRouter } from "react-router";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2022-07-22 19:01:25 +00:00
|
|
|
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";
|
2022-07-22 10:29:22 +00:00
|
|
|
import { isTablet, isMobileOnly } from "react-device-detect";
|
2022-07-22 21:53:40 +00:00
|
|
|
import {
|
|
|
|
StyledArticleProfile,
|
|
|
|
StyledUserName,
|
|
|
|
StyledProfileWrapper,
|
|
|
|
} from "../styled-article";
|
2022-07-12 08:35:06 +00:00
|
|
|
|
2022-07-13 11:03:08 +00:00
|
|
|
const ArticleProfile = (props) => {
|
2022-07-18 18:47:05 +00:00
|
|
|
const { user, showText, getUserRole, getActions } = props;
|
2022-07-11 20:10:44 +00:00
|
|
|
const { t } = useTranslation("Common");
|
2022-07-19 13:12:46 +00:00
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
const ref = useRef(null);
|
|
|
|
const menuRef = useRef(null);
|
2022-07-11 13:18:35 +00:00
|
|
|
|
2022-07-22 10:29:22 +00:00
|
|
|
const isTabletView = (isTabletUtils() || isTablet) && !isMobileOnly;
|
|
|
|
const avatarSize = isTabletView ? "min" : "base";
|
2022-07-12 08:19:31 +00:00
|
|
|
const userRole = getUserRole(user);
|
|
|
|
|
2022-07-19 13:12:46 +00:00
|
|
|
const toggle = (e, isOpen) => {
|
|
|
|
isOpen ? menuRef.current.show(e) : menuRef.current.hide(e);
|
|
|
|
setIsOpen(isOpen);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onAvatarClick = (e) => {
|
2022-07-22 10:29:22 +00:00
|
|
|
if (isTabletView && !showText) toggle(e, !isOpen);
|
2022-07-19 13:12:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const onHide = () => {
|
|
|
|
setIsOpen(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
const model = getActions(t);
|
2022-07-22 09:53:02 +00:00
|
|
|
const username = user.displayName.split(" ");
|
2022-07-19 13:12:46 +00:00
|
|
|
|
2022-07-11 13:18:35 +00:00
|
|
|
return (
|
2022-07-22 21:53:40 +00:00
|
|
|
<StyledProfileWrapper showText={showText}>
|
|
|
|
<StyledArticleProfile showText={showText} tablet={isTabletView}>
|
|
|
|
<div ref={ref}>
|
|
|
|
<Avatar
|
|
|
|
size={avatarSize}
|
|
|
|
role={userRole}
|
|
|
|
source={user.avatar}
|
|
|
|
userName={user.displayName}
|
|
|
|
onClick={onAvatarClick}
|
|
|
|
/>
|
|
|
|
<ContextMenu
|
|
|
|
model={model}
|
|
|
|
containerRef={ref}
|
|
|
|
ref={menuRef}
|
|
|
|
onHide={onHide}
|
|
|
|
scaled={false}
|
|
|
|
leftOffset={-50}
|
2022-07-21 13:41:12 +00:00
|
|
|
/>
|
2022-07-22 21:53:40 +00:00
|
|
|
</div>
|
|
|
|
{(!isTabletView || showText) && (
|
|
|
|
<>
|
|
|
|
<StyledUserName length={user.displayName.length}>
|
|
|
|
<Text fontWeight={600} noSelect truncate>
|
|
|
|
{username[0]}
|
|
|
|
|
|
|
|
</Text>
|
|
|
|
<Text fontWeight={600} noSelect truncate>
|
|
|
|
{username[1]}
|
|
|
|
</Text>
|
|
|
|
</StyledUserName>
|
|
|
|
<ContextMenuButton
|
|
|
|
className="option-button"
|
|
|
|
iconClassName="option-button-icon"
|
|
|
|
zIndex={402}
|
|
|
|
directionX="left"
|
|
|
|
directionY="top"
|
|
|
|
iconName="/static/images/vertical-dots.react.svg"
|
|
|
|
size={32}
|
|
|
|
isFill
|
|
|
|
getData={() => getActions(t)}
|
|
|
|
isDisabled={false}
|
|
|
|
usePortal={true}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</StyledArticleProfile>
|
|
|
|
</StyledProfileWrapper>
|
2022-07-11 13:18:35 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-07-11 20:10:44 +00:00
|
|
|
export default withRouter(
|
2022-07-18 18:47:05 +00:00
|
|
|
inject(({ auth, profileActionsStore }) => {
|
|
|
|
const { getActions, getUserRole } = profileActionsStore;
|
2022-07-11 13:18:35 +00:00
|
|
|
|
2022-07-11 20:10:44 +00:00
|
|
|
return {
|
2022-07-18 18:47:05 +00:00
|
|
|
user: auth.userStore.user,
|
|
|
|
getUserRole,
|
|
|
|
getActions,
|
2022-07-11 20:10:44 +00:00
|
|
|
};
|
2022-07-13 11:03:08 +00:00
|
|
|
})(observer(ArticleProfile))
|
2022-07-11 20:10:44 +00:00
|
|
|
);
|