11import React from 'react' ;
2+ import { useHistory } from 'react-router-dom' ;
23import styled from 'styled-components' ;
34import useProfilePicture from '../../hooks/profile-picture' ;
45import { Link } from 'react-router-dom' ;
@@ -10,6 +11,7 @@ import WaterloopLogoSVG from './assets/topbar-logo.svg';
1011import UnstyledDesktopMenu from './DesktopMenu' ;
1112import UnstyledProfileDropdown from './ProfileDropdown' ;
1213import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown' ;
14+ import useGoogleAuth from '../../hooks/google-auth' ;
1315
1416const AppBar = styled ( MUIAppBar ) `
1517 background-color: ${ ( { theme } ) => theme . colours . blues . blue1 } ;
@@ -56,8 +58,15 @@ const ProfilePicture = styled.img`
5658const TopBar = ( ) => {
5759 const [ menuOpen , setMenuOpen ] = React . useState ( false ) ;
5860 const [ dropdownOpen , setDropdownOpen ] = React . useState ( false ) ;
61+ const { signOut } = useGoogleAuth ( ) ;
62+ const history = useHistory ( ) ;
5963 const { profilePicture } = useProfilePicture ( ) ;
6064
65+ const onLogout = ( ) => {
66+ signOut ( ) ;
67+ history . push ( '/sign-in' ) ;
68+ } ;
69+
6170 return (
6271 < div >
6372 < AppBar position = "relative" >
@@ -86,7 +95,10 @@ const TopBar = () => {
8695 </ AppBar >
8796 { menuOpen && < DesktopMenu onClose = { ( ) => setMenuOpen ( false ) } /> }
8897 { dropdownOpen && (
89- < ProfileDropdown onClose = { ( ) => setDropdownOpen ( false ) } />
98+ < ProfileDropdown
99+ onClose = { ( ) => setDropdownOpen ( false ) }
100+ onLogout = { onLogout }
101+ />
90102 ) }
91103 </ div >
92104 ) ;
0 commit comments