@@ -2,7 +2,8 @@ import { Disclosure, Menu, Transition } from '@headlessui/react';
2
2
import { BellIcon , MenuIcon , XIcon } from '@heroicons/react/outline' ;
3
3
import React , { Fragment } from 'react' ;
4
4
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' ;
6
7
import useProfile from '../../hooks/users' ;
7
8
8
9
const navigation = [
@@ -14,11 +15,23 @@ const navigation = [
14
15
] ;
15
16
const profile = [ 'Your Profile' , 'Settings' , 'Sign out' ] ;
16
17
17
- function classNames ( ...classes : any [ ] ) {
18
- return classes . filter ( Boolean ) . join ( ' ' ) ;
19
- }
18
+ // function classNames(...classes: any[]) {
19
+ // return classes.filter(Boolean).join(' ');
20
+ // }
20
21
21
22
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
+
22
35
// Get Profile
23
36
const {
24
37
isLoading : isProfileLoading ,
@@ -67,6 +80,7 @@ export default function Navbar() {
67
80
// </Fragment>
68
81
// ) : (
69
82
< Link
83
+ key = { item }
70
84
to = { '/' + item . toLowerCase ( ) }
71
85
className = "text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium"
72
86
>
@@ -112,7 +126,7 @@ export default function Navbar() {
112
126
static
113
127
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"
114
128
>
115
- { profile . map ( ( item ) => (
129
+ { /* { profile.map((item) => (
116
130
<Menu.Item key={item}>
117
131
{({ active }) => (
118
132
<a
@@ -126,7 +140,17 @@ export default function Navbar() {
126
140
</a>
127
141
)}
128
142
</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 >
130
154
</ Menu . Items >
131
155
</ Transition >
132
156
</ >
0 commit comments