Skip to content

Commit 58028f4

Browse files
committed
feat: add logout button
1 parent 55db207 commit 58028f4

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/components/Page/Navbar.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Disclosure, Menu, Transition } from '@headlessui/react';
22
import { BellIcon, MenuIcon, XIcon } from '@heroicons/react/outline';
33
import React, { Fragment } from 'react';
44
import Gravatar from 'react-gravatar';
5-
import { Link } from 'react-router-dom';
5+
import { Link, useHistory } from 'react-router-dom';
6+
import useToken from '../../hooks/token';
67
import useProfile from '../../hooks/users';
78

89
const navigation = [
@@ -14,11 +15,23 @@ const navigation = [
1415
];
1516
const profile = ['Your Profile', 'Settings', 'Sign out'];
1617

17-
function classNames(...classes: any[]) {
18-
return classes.filter(Boolean).join(' ');
19-
}
18+
// function classNames(...classes: any[]) {
19+
// return classes.filter(Boolean).join(' ');
20+
// }
2021

2122
export default function Navbar() {
23+
const { setToken } = useToken();
24+
const history = useHistory();
25+
26+
const logOut = (event: any) => {
27+
event.preventDefault();
28+
29+
console.log('called');
30+
31+
setToken('');
32+
history.push('/');
33+
};
34+
2235
// Get Profile
2336
const {
2437
isLoading: isProfileLoading,
@@ -67,6 +80,7 @@ export default function Navbar() {
6780
// </Fragment>
6881
// ) : (
6982
<Link
83+
key={item}
7084
to={'/' + item.toLowerCase()}
7185
className="text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium"
7286
>
@@ -112,7 +126,7 @@ export default function Navbar() {
112126
static
113127
className="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"
114128
>
115-
{profile.map((item) => (
129+
{/* {profile.map((item) => (
116130
<Menu.Item key={item}>
117131
{({ active }) => (
118132
<a
@@ -126,7 +140,17 @@ export default function Navbar() {
126140
</a>
127141
)}
128142
</Menu.Item>
129-
))}
143+
))} */}
144+
<Menu.Item key="logout">
145+
<button
146+
className={
147+
'block px-4 py-2 text-sm text-gray-700'
148+
}
149+
onClick={logOut}
150+
>
151+
Log out
152+
</button>
153+
</Menu.Item>
130154
</Menu.Items>
131155
</Transition>
132156
</>

0 commit comments

Comments
 (0)