aboutsummaryrefslogtreecommitdiff
path: root/src/containers/Profile/MoreMenu.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-08-10 11:19:53 +0300
committereug-vs <eug-vs@keemail.me>2020-08-10 11:19:53 +0300
commitf97989967ee0b88a8c64f226a4b28a79eeef5fd2 (patch)
tree9311246c260705c3c89fded54fb0bb688c98beec /src/containers/Profile/MoreMenu.tsx
parentcab8de5c6b246e1aa1376fa2b8666f09b44b6469 (diff)
downloadwhich-ui-f97989967ee0b88a8c64f226a4b28a79eeef5fd2.tar.gz
refactor: remove "Page" from container names
Diffstat (limited to 'src/containers/Profile/MoreMenu.tsx')
-rw-r--r--src/containers/Profile/MoreMenu.tsx72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/containers/Profile/MoreMenu.tsx b/src/containers/Profile/MoreMenu.tsx
new file mode 100644
index 0000000..1f41879
--- /dev/null
+++ b/src/containers/Profile/MoreMenu.tsx
@@ -0,0 +1,72 @@
+import React from 'react';
+import { useHistory } from 'react-router-dom';
+import IconButton from '@material-ui/core/IconButton';
+import Menu from '@material-ui/core/Menu';
+import MenuItem from '@material-ui/core/MenuItem';
+import MoreHorizIcon from '@material-ui/icons/MoreHoriz';
+import { makeStyles } from '@material-ui/core';
+import { useAuth } from '../../hooks/useAuth';
+
+const ITEM_HEIGHT = 48;
+
+const useStyles = makeStyles({
+ moreMenu: {
+ position: 'absolute',
+ right: 10,
+ zIndex: 100
+ }
+});
+
+const MoreMenu: React.FC = () => {
+ const classes = useStyles();
+ const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
+ const { logout } = useAuth();
+ const history = useHistory();
+
+ const open = Boolean(anchorEl);
+
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
+ setAnchorEl(event.currentTarget);
+ };
+
+ const handleLogout = () => {
+ logout();
+ history.push('/login');
+ };
+
+ const handleClose = () => {
+ setAnchorEl(null);
+ };
+
+ return (
+ <div className={classes.moreMenu}>
+ <div>
+ <IconButton
+ aria-label="more"
+ aria-controls="long-menu"
+ aria-haspopup="true"
+ onClick={handleClick}
+ >
+ <MoreHorizIcon />
+ </IconButton>
+ <Menu
+ id="long-menu"
+ anchorEl={anchorEl}
+ keepMounted
+ open={open}
+ onClose={handleClose}
+ PaperProps={{
+ style: {
+ maxHeight: ITEM_HEIGHT * 4.5,
+ width: '20ch'
+ }
+ }}
+ >
+ <MenuItem onClick={handleLogout}>Log out</MenuItem>
+ </Menu>
+ </div>
+ </div>
+ );
+};
+
+export default MoreMenu;