2021-02-03 11:49:51 -08:00
|
|
|
import React from 'react';
|
2021-02-18 14:16:57 -05:00
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
import { Menu, Avatar, Dropdown } from 'antd';
|
2021-04-09 03:30:13 +08:00
|
|
|
import { CaretDownOutlined } from '@ant-design/icons';
|
2021-01-17 12:54:49 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
2021-04-09 03:30:13 +08:00
|
|
|
import styled, { useTheme } from 'styled-components';
|
2021-01-17 12:54:49 -08:00
|
|
|
import defaultAvatar from '../../images/default_avatar.png';
|
2021-02-03 11:49:51 -08:00
|
|
|
import { EntityType } from '../../types.generated';
|
|
|
|
import { useEntityRegistry } from '../useEntityRegistry';
|
2021-03-11 13:38:35 -08:00
|
|
|
import { GlobalCfg } from '../../conf';
|
2021-03-23 03:14:14 +05:30
|
|
|
import { isLoggedInVar } from '../auth/checkAuthStatus';
|
2021-01-17 12:54:49 -08:00
|
|
|
|
2021-04-09 03:30:13 +08:00
|
|
|
const MenuItem = styled(Menu.Item)`
|
|
|
|
&& {
|
|
|
|
margin-top: 2px;
|
|
|
|
}
|
|
|
|
& > a:visited,
|
|
|
|
& > a:active,
|
|
|
|
& > a:focus {
|
|
|
|
clear: both;
|
|
|
|
border: none;
|
|
|
|
outline: 0;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
const AvatarCircle = styled(Avatar)`
|
|
|
|
color: #f56a00;
|
|
|
|
margin-right: 5px;
|
|
|
|
background-color: #fde3cf;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const DownArrow = styled(CaretDownOutlined)`
|
|
|
|
font-size: 18px;
|
|
|
|
color: #fff;
|
|
|
|
`;
|
|
|
|
|
2021-01-17 12:54:49 -08:00
|
|
|
interface Props {
|
|
|
|
urn: string;
|
|
|
|
pictureLink?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
pictureLink: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ManageAccount = ({ urn: _urn, pictureLink: _pictureLink }: Props) => {
|
2021-02-03 11:49:51 -08:00
|
|
|
const entityRegistry = useEntityRegistry();
|
2021-03-23 03:14:14 +05:30
|
|
|
const themeConfig = useTheme();
|
2021-02-18 14:16:57 -05:00
|
|
|
const handleLogout = () => {
|
|
|
|
isLoggedInVar(false);
|
2021-03-11 13:38:35 -08:00
|
|
|
Cookies.remove(GlobalCfg.CLIENT_AUTH_COOKIE);
|
2021-02-18 14:16:57 -05:00
|
|
|
};
|
2021-04-09 03:30:13 +08:00
|
|
|
|
2021-02-18 14:16:57 -05:00
|
|
|
const menu = (
|
|
|
|
<Menu>
|
2021-03-23 03:14:14 +05:30
|
|
|
{themeConfig.content.menu.items.map((value) => {
|
|
|
|
return (
|
2021-04-09 03:30:13 +08:00
|
|
|
<MenuItem key={value.label}>
|
|
|
|
<a
|
|
|
|
href={value.path || ''}
|
|
|
|
target={value.shouldOpenInNewTab ? '_blank' : ''}
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
tabIndex={0}
|
|
|
|
>
|
|
|
|
{value.label}
|
2021-03-23 03:14:14 +05:30
|
|
|
</a>
|
2021-04-09 03:30:13 +08:00
|
|
|
</MenuItem>
|
2021-03-23 03:14:14 +05:30
|
|
|
);
|
|
|
|
})}
|
2021-04-09 03:30:13 +08:00
|
|
|
<MenuItem danger key="logout" onClick={handleLogout} tabIndex={0}>
|
|
|
|
Log out
|
|
|
|
</MenuItem>
|
2021-02-18 14:16:57 -05:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
|
2021-01-17 12:54:49 -08:00
|
|
|
return (
|
2021-02-18 14:16:57 -05:00
|
|
|
<Dropdown overlay={menu}>
|
|
|
|
<Link to={`/${entityRegistry.getPathName(EntityType.CorpUser)}/${_urn}`}>
|
2021-04-09 03:30:13 +08:00
|
|
|
<AvatarCircle src={_pictureLink || defaultAvatar} />
|
|
|
|
<DownArrow />
|
2021-02-18 14:16:57 -05:00
|
|
|
</Link>
|
|
|
|
</Dropdown>
|
2021-01-17 12:54:49 -08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ManageAccount.defaultProps = defaultProps;
|