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-01-17 12:54:49 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
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-02-18 14:16:57 -05:00
|
|
|
import { isLoggedInVar } from '../auth/checkAuthStatus';
|
2021-03-11 13:38:35 -08:00
|
|
|
import { GlobalCfg } from '../../conf';
|
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-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
|
|
|
};
|
|
|
|
|
|
|
|
const menu = (
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item danger>
|
|
|
|
<div tabIndex={0} role="button" onClick={handleLogout} onKeyDown={handleLogout}>
|
|
|
|
Log out
|
|
|
|
</div>
|
|
|
|
</Menu.Item>
|
|
|
|
</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}`}>
|
|
|
|
<Avatar
|
|
|
|
style={{
|
|
|
|
marginRight: '15px',
|
|
|
|
color: '#f56a00',
|
|
|
|
backgroundColor: '#fde3cf',
|
|
|
|
}}
|
|
|
|
src={_pictureLink || defaultAvatar}
|
|
|
|
/>
|
|
|
|
</Link>
|
|
|
|
</Dropdown>
|
2021-01-17 12:54:49 -08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ManageAccount.defaultProps = defaultProps;
|