5 Commits

Author SHA1 Message Date
ToanDo
0439b052ca fixed spelling 2020-12-24 14:18:22 -05:00
ToanDo
448a198c23 adjusted component 2020-12-24 14:17:11 -05:00
ToanDo
f989132de6 fixed usersDropdown import 2020-12-24 14:05:15 -05:00
ToanDo
a6406e2be3 test passing down component 2020-12-23 16:59:20 -05:00
ToanDo
0748ddbed1 added currentUserEmail prop & alter Account title 2020-12-16 13:07:39 -05:00
3 changed files with 71 additions and 2 deletions

View File

@@ -0,0 +1,58 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { Popover, Row } from 'antd';
import { UserOutlined } from '@ant-design/icons';
import styles from './index.module.scss';
const UsersDropdown = ({ onLogout }) => {
const [popoverVisible, setPopoverVisible] = useState(false);
const hidePopover = () => {
setPopoverVisible(false);
};
const handleVisibleChange = visible => {
setPopoverVisible(visible);
};
const userOptions = (
<>
<Row>
<Link onClick={hidePopover} to="/account">
Account
</Link>
</Row>
<Row>
<Link onClick={onLogout} to="/">
Log Out
</Link>
</Row>
</>
);
return (
<Popover
content={userOptions}
trigger="click"
getPopupContainer={e => e.parentElement}
visible={popoverVisible}
onVisibleChange={handleVisibleChange}
placement="bottomRight"
arrowPointAtCenter
>
<UserOutlined className={styles.MenuIcon} />
</Popover>
);
};
UsersDropdown.propTypes = {
onLogout: PropTypes.func,
};
UsersDropdown.defaultProps = {
onLogout: () => {},
};
export default UsersDropdown;

View File

@@ -0,0 +1,7 @@
.MenuIcon {
cursor: pointer;
font-size: 18px;
line-height: 64px;
padding: 0 24px;
}

View File

@@ -12,8 +12,10 @@ import { removeItem } from 'utils/localStorage';
import UserContext from 'contexts/UserContext';
import UsersDropdown from 'components/UsersDropdown';
const MasterLayout = ({ children }) => {
const { roles, customerId } = useContext(UserContext);
const { roles, customerId, email } = useContext(UserContext);
const client = useApolloClient();
const location = useLocation();
@@ -59,7 +61,7 @@ const MasterLayout = ({ children }) => {
{
key: 'editAccount',
path: ROUTES.account,
text: 'Edit Account',
text: 'Account',
},
{
key: 'logout',
@@ -90,6 +92,8 @@ const MasterLayout = ({ children }) => {
menuItems={menuItems}
mobileMenuItems={mobileMenuItems}
totalAlarms={data && data.getAlarmCount}
currentUserEmail={email}
usersDropdown={<UsersDropdown onLogout={handleLogout} />}
>
{children}
</Layout>