From 1f646377c35b65b97d6eeebb1e88f6d8307e1ef0 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 29 Jun 2020 23:59:15 +0300
Subject: feat!: create useAuth hook

---
 src/pages/ProfilePage/MoreMenu.tsx | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

(limited to 'src/pages/ProfilePage/MoreMenu.tsx')

diff --git a/src/pages/ProfilePage/MoreMenu.tsx b/src/pages/ProfilePage/MoreMenu.tsx
index bf3347b..7c17f1e 100644
--- a/src/pages/ProfilePage/MoreMenu.tsx
+++ b/src/pages/ProfilePage/MoreMenu.tsx
@@ -4,10 +4,7 @@ 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';
-
-interface PropTypes {
-  logOut: () => void;
-}
+import { useAuth } from '../../hooks/useAuth';
 
 const ITEM_HEIGHT = 48;
 
@@ -19,9 +16,11 @@ const useStyles = makeStyles({
   }
 });
 
-const MoreMenu: React.FC<PropTypes> = ({ logOut }) => {
+const MoreMenu: React.FC = () => {
   const classes = useStyles();
   const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
+  const { logout } = useAuth();
+
   const open = Boolean(anchorEl);
 
   const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
@@ -56,7 +55,7 @@ const MoreMenu: React.FC<PropTypes> = ({ logOut }) => {
             }
           }}
         >
-          <MenuItem onClick={logOut}>Log out</MenuItem>
+          <MenuItem onClick={logout}>Log out</MenuItem>
         </Menu>
       </div>
     </div>
-- 
cgit v1.2.3


From b31ed66aafbe1d5dbe70d0cdfd70864204510d81 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Tue, 30 Jun 2020 01:27:39 +0300
Subject: fix: re-implement navigation logic

---
 src/pages/ProfilePage/MoreMenu.tsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'src/pages/ProfilePage/MoreMenu.tsx')

diff --git a/src/pages/ProfilePage/MoreMenu.tsx b/src/pages/ProfilePage/MoreMenu.tsx
index 7c17f1e..4e681f5 100644
--- a/src/pages/ProfilePage/MoreMenu.tsx
+++ b/src/pages/ProfilePage/MoreMenu.tsx
@@ -5,6 +5,7 @@ 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';
+import { useNavigate } from '../../hooks/useNavigate';
 
 const ITEM_HEIGHT = 48;
 
@@ -20,6 +21,7 @@ const MoreMenu: React.FC = () => {
   const classes = useStyles();
   const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
   const { logout } = useAuth();
+  const { navigate } = useNavigate();
 
   const open = Boolean(anchorEl);
 
@@ -27,6 +29,11 @@ const MoreMenu: React.FC = () => {
     setAnchorEl(event.currentTarget);
   };
 
+  const handleLogout = () => {
+    logout();
+    navigate('auth');
+  };
+
   const handleClose = () => {
     setAnchorEl(null);
   };
@@ -55,7 +62,7 @@ const MoreMenu: React.FC = () => {
             }
           }}
         >
-          <MenuItem onClick={logout}>Log out</MenuItem>
+          <MenuItem onClick={handleLogout}>Log out</MenuItem>
         </Menu>
       </div>
     </div>
-- 
cgit v1.2.3

