2020-09-23 14:06:50 +00:00
|
|
|
import React, { Fragment } from "react";
|
2020-09-26 13:22:15 +00:00
|
|
|
import { CommonComponentProps, Classes } from "components/ads/common";
|
2020-09-22 11:56:11 +00:00
|
|
|
import Text, { TextType } from "components/ads/Text";
|
2020-09-23 14:06:50 +00:00
|
|
|
import styled, { createGlobalStyle } from "styled-components";
|
2021-03-04 09:37:02 +00:00
|
|
|
import { Position, Classes as BlueprintClasses } from "@blueprintjs/core";
|
2020-09-22 11:56:11 +00:00
|
|
|
import Menu from "components/ads/Menu";
|
|
|
|
|
import ThemeSwitcher from "./ThemeSwitcher";
|
|
|
|
|
import MenuDivider from "components/ads/MenuDivider";
|
|
|
|
|
import MenuItem from "components/ads/MenuItem";
|
|
|
|
|
import {
|
|
|
|
|
getOnSelectAction,
|
|
|
|
|
DropdownOnSelectActions,
|
|
|
|
|
} from "./CustomizedDropdown/dropdownHelpers";
|
|
|
|
|
import { ReduxActionTypes } from "constants/ReduxActionConstants";
|
2020-11-11 13:12:05 +00:00
|
|
|
import ProfileImage from "./ProfileImage";
|
2021-02-04 07:02:36 +00:00
|
|
|
import { PopperModifiers } from "@blueprintjs/core";
|
2021-03-04 09:37:02 +00:00
|
|
|
import { PROFILE } from "constants/routes";
|
2020-09-22 11:56:11 +00:00
|
|
|
|
|
|
|
|
type TagProps = CommonComponentProps & {
|
|
|
|
|
onClick?: (text: string) => void;
|
|
|
|
|
userName?: string;
|
2021-03-04 09:37:02 +00:00
|
|
|
name: string;
|
2021-02-04 07:02:36 +00:00
|
|
|
hideThemeSwitch?: boolean;
|
|
|
|
|
modifiers?: PopperModifiers;
|
2020-09-22 11:56:11 +00:00
|
|
|
};
|
|
|
|
|
|
2020-09-23 14:06:50 +00:00
|
|
|
const ProfileMenuStyle = createGlobalStyle`
|
2020-10-14 10:35:19 +00:00
|
|
|
.bp3-popover {
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
}
|
2020-09-23 14:06:50 +00:00
|
|
|
.profile-menu {
|
|
|
|
|
.bp3-popover .bp3-popover-content{
|
|
|
|
|
margin-top: 2px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-09-26 13:22:15 +00:00
|
|
|
const UserInformation = styled.div`
|
2020-12-24 04:32:25 +00:00
|
|
|
padding: ${(props) => props.theme.spaces[6]}px;
|
2020-09-26 13:22:15 +00:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
.user-username {
|
|
|
|
|
flex-basis: 60%;
|
2020-09-26 13:22:15 +00:00
|
|
|
white-space: nowrap;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
.${Classes.TEXT} {
|
2020-12-24 04:32:25 +00:00
|
|
|
color: ${(props) => props.theme.colors.profileDropdown.userName};
|
2020-09-26 13:22:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
.user-name {
|
|
|
|
|
flex-basis: 60%;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
.${Classes.TEXT} {
|
|
|
|
|
color: ${(props) => props.theme.colors.profileDropdown.name};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-26 13:22:15 +00:00
|
|
|
.user-image {
|
2020-12-24 04:32:25 +00:00
|
|
|
margin-right: ${(props) => props.theme.spaces[4]}px;
|
2020-09-26 13:22:15 +00:00
|
|
|
div {
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
const UserNameWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
// To make flex child fit in container
|
|
|
|
|
min-width: 0;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-09-22 11:56:11 +00:00
|
|
|
export default function ProfileDropdown(props: TagProps) {
|
2020-11-11 13:12:05 +00:00
|
|
|
const Profile = <ProfileImage userName={props.userName} />;
|
2020-09-22 11:56:11 +00:00
|
|
|
|
|
|
|
|
return (
|
2020-09-23 14:06:50 +00:00
|
|
|
<Fragment>
|
|
|
|
|
<ProfileMenuStyle />
|
|
|
|
|
<Menu
|
2021-03-04 09:37:02 +00:00
|
|
|
className="profile-menu t--profile-menu"
|
2020-09-23 14:06:50 +00:00
|
|
|
position={Position.BOTTOM}
|
2020-09-26 13:22:15 +00:00
|
|
|
target={Profile}
|
2021-02-04 07:02:36 +00:00
|
|
|
modifiers={props.modifiers}
|
2020-09-23 14:06:50 +00:00
|
|
|
>
|
2020-09-26 13:22:15 +00:00
|
|
|
<UserInformation>
|
|
|
|
|
<div className="user-image">{Profile}</div>
|
2021-03-04 09:37:02 +00:00
|
|
|
<UserNameWrapper>
|
|
|
|
|
<div className="user-name t--user-name">
|
|
|
|
|
<Text type={TextType.P1} highlight>
|
|
|
|
|
{props.name}
|
|
|
|
|
</Text>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="user-username">
|
|
|
|
|
<Text type={TextType.P3} highlight>
|
|
|
|
|
{props.userName}
|
|
|
|
|
</Text>
|
|
|
|
|
</div>
|
|
|
|
|
</UserNameWrapper>
|
2020-09-26 13:22:15 +00:00
|
|
|
</UserInformation>
|
|
|
|
|
<MenuDivider />
|
2021-02-04 07:02:36 +00:00
|
|
|
{!props.hideThemeSwitch && (
|
|
|
|
|
<>
|
|
|
|
|
<ThemeSwitcher />
|
|
|
|
|
<MenuDivider />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2021-03-04 09:37:02 +00:00
|
|
|
<MenuItem
|
|
|
|
|
icon="edit"
|
|
|
|
|
text="Edit Profile"
|
|
|
|
|
className={`t--edit-profile ${BlueprintClasses.POPOVER_DISMISS}`}
|
|
|
|
|
onSelect={() => {
|
|
|
|
|
getOnSelectAction(DropdownOnSelectActions.REDIRECT, {
|
|
|
|
|
path: PROFILE,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2020-09-23 14:06:50 +00:00
|
|
|
<MenuItem
|
|
|
|
|
icon="logout"
|
|
|
|
|
text="Sign Out"
|
2020-10-19 13:34:55 +00:00
|
|
|
className="t--logout-icon"
|
2020-09-23 14:06:50 +00:00
|
|
|
onSelect={() =>
|
|
|
|
|
getOnSelectAction(DropdownOnSelectActions.DISPATCH, {
|
|
|
|
|
type: ReduxActionTypes.LOGOUT_USER_INIT,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Menu>
|
|
|
|
|
</Fragment>
|
2020-09-22 11:56:11 +00:00
|
|
|
);
|
|
|
|
|
}
|