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';
|
2021-04-10 07:53:04 +08:00
|
|
|
import { Menu, Dropdown } from 'antd';
|
2021-04-09 03:30:13 +08:00
|
|
|
import { CaretDownOutlined } from '@ant-design/icons';
|
|
|
|
import styled, { useTheme } from 'styled-components';
|
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-04-10 07:53:04 +08:00
|
|
|
import CustomAvatar from './avatar/CustomAvatar';
|
2021-05-11 15:41:42 -07:00
|
|
|
import analytics, { EventType } from '../analytics';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { ANTD_GRAY } from '../entity/shared/constants';
|
2022-01-11 15:00:57 -08:00
|
|
|
import { useAppConfig } from '../useAppConfig';
|
2021-01-17 12:54:49 -08:00
|
|
|
|
2021-04-09 03:30:13 +08:00
|
|
|
const MenuItem = styled(Menu.Item)`
|
2022-07-02 01:00:06 +05:30
|
|
|
display: flex;
|
|
|
|
justify-content: start;
|
|
|
|
align-items: center;
|
2021-04-09 03:30:13 +08:00
|
|
|
&& {
|
|
|
|
margin-top: 2px;
|
|
|
|
}
|
|
|
|
& > a:visited,
|
|
|
|
& > a:active,
|
|
|
|
& > a:focus {
|
|
|
|
clear: both;
|
|
|
|
border: none;
|
|
|
|
outline: 0;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const DownArrow = styled(CaretDownOutlined)`
|
2022-06-03 07:47:39 -07:00
|
|
|
vertical-align: -1px;
|
|
|
|
font-size: 10px;
|
2021-08-31 22:00:56 -07:00
|
|
|
color: ${ANTD_GRAY[7]};
|
2021-04-09 03:30:13 +08:00
|
|
|
`;
|
|
|
|
|
2022-07-01 17:45:44 -04:00
|
|
|
const DropdownWrapper = styled.div`
|
|
|
|
align-items: center;
|
|
|
|
cursor: pointer;
|
|
|
|
display: flex;
|
|
|
|
`;
|
|
|
|
|
2021-01-17 12:54:49 -08:00
|
|
|
interface Props {
|
|
|
|
urn: string;
|
|
|
|
pictureLink?: string;
|
2021-04-10 07:53:04 +08:00
|
|
|
name?: string;
|
2021-01-17 12:54:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
pictureLink: undefined,
|
|
|
|
};
|
|
|
|
|
2021-04-10 07:53:04 +08:00
|
|
|
export const ManageAccount = ({ urn: _urn, pictureLink: _pictureLink, name }: Props) => {
|
2021-02-03 11:49:51 -08:00
|
|
|
const entityRegistry = useEntityRegistry();
|
2021-03-23 03:14:14 +05:30
|
|
|
const themeConfig = useTheme();
|
2022-01-11 15:00:57 -08:00
|
|
|
const { config } = useAppConfig();
|
2021-02-18 14:16:57 -05:00
|
|
|
const handleLogout = () => {
|
2021-05-11 15:41:42 -07:00
|
|
|
analytics.event({ type: EventType.LogOutEvent });
|
2021-02-18 14:16:57 -05:00
|
|
|
isLoggedInVar(false);
|
2021-03-11 13:38:35 -08:00
|
|
|
Cookies.remove(GlobalCfg.CLIENT_AUTH_COOKIE);
|
2021-02-18 14:16:57 -05:00
|
|
|
};
|
2022-01-11 15:00:57 -08:00
|
|
|
const version = config?.appVersion;
|
2021-02-18 14:16:57 -05:00
|
|
|
const menu = (
|
2022-07-02 01:00:06 +05:30
|
|
|
<Menu style={{ width: '120px' }}>
|
|
|
|
{version && (
|
|
|
|
<MenuItem key="version" disabled style={{ color: '#8C8C8C' }}>
|
|
|
|
{version}
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
<Menu.Divider />
|
|
|
|
<MenuItem key="profile">
|
|
|
|
<a
|
|
|
|
href={`/${entityRegistry.getPathName(EntityType.CorpUser)}/${_urn}`}
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
tabIndex={0}
|
|
|
|
>
|
|
|
|
Your Profile
|
|
|
|
</a>
|
|
|
|
</MenuItem>
|
|
|
|
<Menu.Divider />
|
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
|
|
|
);
|
|
|
|
})}
|
2022-02-24 19:40:55 -08:00
|
|
|
<MenuItem key="graphiQLLink">
|
|
|
|
<a href="/api/graphiql">GraphiQL</a>
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem key="openapiLink">
|
|
|
|
<a href="/openapi/swagger-ui/index.html">OpenAPI</a>
|
|
|
|
</MenuItem>
|
2022-07-02 01:00:06 +05:30
|
|
|
<Menu.Divider />
|
2021-08-16 12:19:44 +07:00
|
|
|
<MenuItem danger key="logout" tabIndex={0}>
|
2022-08-01 19:23:03 -07:00
|
|
|
<a href="/logOut" onClick={handleLogout}>
|
2022-07-02 01:00:06 +05:30
|
|
|
Sign Out
|
2021-08-16 12:19:44 +07:00
|
|
|
</a>
|
2021-04-09 03:30:13 +08:00
|
|
|
</MenuItem>
|
2021-02-18 14:16:57 -05:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
|
2021-01-17 12:54:49 -08:00
|
|
|
return (
|
2022-07-01 17:45:44 -04:00
|
|
|
<Dropdown overlay={menu} trigger={['click']}>
|
|
|
|
<DropdownWrapper>
|
|
|
|
<CustomAvatar photoUrl={_pictureLink} style={{ marginRight: 4 }} name={name} />
|
2021-04-09 03:30:13 +08:00
|
|
|
<DownArrow />
|
2022-07-01 17:45:44 -04:00
|
|
|
</DropdownWrapper>
|
|
|
|
</Dropdown>
|
2021-01-17 12:54:49 -08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ManageAccount.defaultProps = defaultProps;
|