2019-10-08 12:47:11 +07:00
|
|
|
import React, { MouseEvent } from 'react';
|
|
|
|
import AccountCircle from '@material-ui/icons/AccountCircle';
|
|
|
|
|
2019-10-12 13:45:39 +07:00
|
|
|
import IconButton from '../../muiComponents/IconButton';
|
2019-10-31 14:12:18 +07:00
|
|
|
import MenuItem from '../../muiComponents/MenuItem';
|
|
|
|
import Menu from '../../muiComponents/Menu';
|
2019-10-12 13:45:39 +07:00
|
|
|
|
2019-10-08 12:47:11 +07:00
|
|
|
import HeaderGreetings from './HeaderGreetings';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
username: string;
|
|
|
|
isMenuOpen: boolean;
|
|
|
|
anchorEl?: Element | ((element: Element) => Element) | null | undefined;
|
|
|
|
onLogout: () => void;
|
|
|
|
onLoggedInMenu: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
|
|
onLoggedInMenuClose: () => void;
|
|
|
|
}
|
|
|
|
|
2019-10-27 21:49:30 +07:00
|
|
|
const HeaderMenu: React.FC<Props> = ({
|
|
|
|
onLogout,
|
|
|
|
username,
|
|
|
|
isMenuOpen = false,
|
|
|
|
anchorEl,
|
|
|
|
onLoggedInMenu,
|
|
|
|
onLoggedInMenuClose,
|
|
|
|
}) => (
|
2019-10-08 12:47:11 +07:00
|
|
|
<>
|
2019-10-27 21:49:30 +07:00
|
|
|
<IconButton
|
|
|
|
color="inherit"
|
2019-11-25 01:21:08 +07:00
|
|
|
data-testid="header--menu-accountcircle"
|
2019-10-27 21:49:30 +07:00
|
|
|
id="header--button-account"
|
|
|
|
onClick={onLoggedInMenu}>
|
2019-10-08 12:47:11 +07:00
|
|
|
<AccountCircle />
|
|
|
|
</IconButton>
|
|
|
|
<Menu
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
anchorOrigin={{
|
|
|
|
vertical: 'top',
|
|
|
|
horizontal: 'right',
|
|
|
|
}}
|
|
|
|
onClose={onLoggedInMenuClose}
|
|
|
|
open={isMenuOpen}
|
|
|
|
transformOrigin={{
|
|
|
|
vertical: 'top',
|
|
|
|
horizontal: 'right',
|
|
|
|
}}>
|
|
|
|
<MenuItem disabled={true}>
|
|
|
|
<HeaderGreetings username={username} />
|
|
|
|
</MenuItem>
|
2019-11-25 01:21:08 +07:00
|
|
|
<MenuItem button={true} data-testid="header--button-logout" id="header--button-logout" onClick={onLogout}>
|
2019-10-08 12:47:11 +07:00
|
|
|
{'Logout'}
|
|
|
|
</MenuItem>
|
|
|
|
</Menu>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default HeaderMenu;
|