@@ -17,12 +17,14 @@ import { MdOutlineSpaceDashboard } from 'react-icons/md';
17
17
import { TfiDashboard } from 'react-icons/tfi' ;
18
18
import { HiBars3 } from 'react-icons/hi2' ;
19
19
import { AiFillCloseCircle } from 'react-icons/ai' ;
20
+ import { CgProfile } from 'react-icons/cg' ;
21
+ import { BiLogIn } from 'react-icons/bi' ;
20
22
21
23
const UserMenuItems = ( {
22
24
user,
23
25
setMobileMenuOpen,
24
26
} : {
25
- user ?: { isAdmin : boolean } ; // Adjust the type based on your actual user structure
27
+ user ?: string ; // Adjust the type based on your actual user structure
26
28
setMobileMenuOpen ?: React . Dispatch < React . SetStateAction < boolean > > ;
27
29
} ) => {
28
30
const path = window . location . pathname ;
@@ -42,7 +44,7 @@ const UserMenuItems = ({
42
44
>
43
45
{ path === '/' || path === '/admin' ? (
44
46
< li >
45
- < Link href = '/demo-app' >
47
+ < Link href = '/demo-app' legacyBehavior >
46
48
< a className = 'flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500' >
47
49
< MdOutlineSpaceDashboard size = '1.1rem' />
48
50
AI Scheduler (Demo App)
@@ -51,7 +53,7 @@ const UserMenuItems = ({
51
53
</ li >
52
54
) : null }
53
55
< li >
54
- < Link href = '/account' >
56
+ < Link href = '/account' legacyBehavior >
55
57
< a
56
58
onClick = { handleMobileMenuClick }
57
59
className = 'flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500'
@@ -78,14 +80,13 @@ const UserMenuItems = ({
78
80
</ Link >
79
81
</ li >
80
82
</ ul >
81
- { ! ! user ?. isAdmin && (
82
83
< ul
83
84
className = { `flex flex-col gap-5 border-b border-stroke py-4 dark:border-strokedark ${
84
85
path === '/admin' ? 'px-6' : 'sm:px-6'
85
86
} `}
86
87
>
87
88
< li className = 'flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500' >
88
- < Link href = '/admin' >
89
+ < Link href = '/admin' legacyBehavior >
89
90
< a
90
91
onClick = { handleMobileMenuClick }
91
92
className = 'flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500'
@@ -96,7 +97,6 @@ const UserMenuItems = ({
96
97
</ Link >
97
98
</ li >
98
99
</ ul >
99
- ) }
100
100
< button
101
101
className = { `flex items-center gap-3.5 py-4 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500 ${
102
102
path === '/admin' ? 'px-6' : 'sm:px-6'
@@ -126,13 +126,75 @@ const UserMenuItems = ({
126
126
} ;
127
127
128
128
const UserDropdownMenu = ( { user } : { user : string } ) => {
129
- const supabase = useSupabaseClient ( ) ;
130
129
const session = useSession ( ) ;
130
+ const supabase = useSupabaseClient ( ) ;
131
+ const [ profile , setProfile ] = useState < any > ( null ) ;
132
+
133
+ useEffect ( ( ) => {
134
+ supabase
135
+ . from ( "profiles" )
136
+ . select ( )
137
+ . eq ( "id" , session ?. user ?. id )
138
+ . then ( ( result ) => {
139
+ if ( result . data ) {
140
+ setProfile ( result . data [ 0 ] ) ;
141
+ }
142
+ } ) ;
143
+ } , [ session ] ) ;
131
144
132
145
const [ dropdownOpen , setDropdownOpen ] = useState ( false ) ;
133
146
const trigger = useRef < any > ( null ) ;
134
147
const dropdown = useRef < any > ( null ) ;
135
148
const toggleDropdown = ( ) => setDropdownOpen ( ( prev ) => ! prev ) ;
149
+
150
+ useEffect ( ( ) => {
151
+ const keyHandler = ( { keyCode } : KeyboardEvent ) => {
152
+ if ( ! dropdownOpen || keyCode !== 27 ) return ;
153
+ setDropdownOpen ( false ) ;
154
+ } ;
155
+ document . addEventListener ( 'keydown' , keyHandler ) ;
156
+ return ( ) => document . removeEventListener ( 'keydown' , keyHandler ) ;
157
+ } ) ;
158
+
159
+ return (
160
+ < div className = 'relative' >
161
+ < button
162
+ ref = { trigger }
163
+ onClick = { toggleDropdown }
164
+ className = 'flex items-center gap-4 duration-300 ease-in-out text-gray-900 hover:text-yellow-500'
165
+ >
166
+ < span className = 'hidden text-right lg:block' >
167
+ < span className = 'block text-sm font-medium dark:text-white' > { profile ?. username } </ span >
168
+ </ span >
169
+ < CgProfile size = '1.1rem' className = 'ml-1 mt-[0.1rem] dark:text-white' />
170
+ < svg
171
+ className = { `hidden fill-current dark:fill-white sm:block ${ dropdownOpen ? 'rotate-180' : '' } ` }
172
+ width = '12'
173
+ height = '8'
174
+ viewBox = '0 0 12 8'
175
+ fill = 'none'
176
+ xmlns = 'http://www.w3.org/2000/svg'
177
+ >
178
+ < path
179
+ fillRule = 'evenodd'
180
+ clipRule = 'evenodd'
181
+ d = 'M0.410765 0.910734C0.736202 0.585297 1.26384 0.585297 1.58928 0.910734L6.00002 5.32148L10.4108 0.910734C10.7362 0.585297 11.2638 0.585297 11.5893 0.910734C11.9147 1.23617 11.9147 1.76381 11.5893 2.08924L6.58928 7.08924C6.26384 7.41468 5.7362 7.41468 5.41077 7.08924L0.410765 2.08924C0.0853277 1.76381 0.0853277 1.23617 0.410765 0.910734Z'
182
+ fill = ''
183
+ />
184
+ </ svg >
185
+ </ button >
186
+
187
+ { /* <!-- Dropdown --> */ }
188
+ < div
189
+ ref = { dropdown }
190
+ className = { `absolute right-0 mt-4 flex w-62.5 flex-col rounded-sm border border-stroke bg-white shadow-default dark:border-strokedark dark:bg-boxdark dark:text-white ${
191
+ dropdownOpen === true ? 'block' : 'hidden'
192
+ } `}
193
+ >
194
+ < UserMenuItems user = { session ?. user ?. id } setMobileMenuOpen = { toggleDropdown } />
195
+ </ div >
196
+ </ div >
197
+ ) ;
136
198
}
137
199
138
200
const navigation = [
@@ -155,10 +217,26 @@ const NavLogo = () => (
155
217
) ;
156
218
157
219
export default function Navigation ( ) {
220
+ const session = useSession ( ) ;
221
+ const supabase = useSupabaseClient ( ) ;
222
+ const [ profile , setProfile ] = useState < any > ( null ) ;
223
+
224
+ useEffect ( ( ) => {
225
+ supabase
226
+ . from ( "profiles" )
227
+ . select ( )
228
+ . eq ( "id" , session ?. user ?. id )
229
+ . then ( ( result ) => {
230
+ if ( result . data ) {
231
+ setProfile ( result . data [ 0 ] ) ;
232
+ }
233
+ } ) ;
234
+ } , [ session ] ) ;
235
+
158
236
const [ mobileMenuOpen , setMobileMenuOpen ] = useState ( false ) ;
159
237
160
238
return (
161
- < header className = 'absolute inset-x-0 top-0 z-50 shadow sticky bg-white bg-opacity-50 backdrop-blur-lg backdrop-filter dark:border-strokedark dark:bg-boxdark-2' >
239
+ < header className = 'absolute inset-x-0 top-0 z-50 shadow sticky backdrop-blur-lg bg-opacity-40 backdrop-filter dark:border-strokedark dark:bg-boxdark-2' >
162
240
< nav
163
241
className = 'flex items-center justify-between p-6 lg:px-8'
164
242
aria-label = 'Global'
@@ -193,7 +271,18 @@ export default function Navigation() {
193
271
< ul className = 'flex justify-center items-center gap-2 sm:gap-4' >
194
272
{ /* <DarkModeSwitcher /> */ }
195
273
</ ul >
196
-
274
+ < a
275
+ href = { ! session ? '/login' : '/account' }
276
+ className = 'text-sm font-semibold leading-6 ml-4'
277
+ >
278
+ { /* <div className='flex items-center duration-300 ease-in-out text-gray-900 hover:text-yellow-500 dark:text-white'>
279
+ Log in <BiLogIn size='1.1rem' className='ml-1 mt-[0.1rem]' />
280
+ </div> */ }
281
+ </ a >
282
+ { /* ) : ( */ }
283
+ < div className = 'ml-4' >
284
+ < UserDropdownMenu user = { session ?. user ?. id } />
285
+ </ div >
197
286
{ /* {isUserLoading ? null : !user ? (
198
287
<a
199
288
href={!user ? '/login' : '/account'}
@@ -262,8 +351,8 @@ export default function Navigation() {
262
351
</ Dialog . Panel >
263
352
</ Dialog >
264
353
</ header >
265
- )
266
- }
354
+ ) ;
355
+ } ;
267
356
268
357
const products = [
269
358
{ name : 'Your planets' , description : '' , href : '/garden' , icon : ChartPieIcon } ,
0 commit comments