1
1
'use client'
2
2
3
3
import {
4
+ Bell ,
4
5
Calculator ,
5
- Calendar ,
6
6
CreditCard ,
7
- Settings ,
8
7
Smile ,
9
8
User
10
9
} from 'lucide-react'
11
- import * as React from 'react'
10
+ import Link from 'next/link'
11
+ import { useEffect , useState } from 'react'
12
12
13
13
import {
14
14
CommandDialog ,
@@ -17,14 +17,21 @@ import {
17
17
CommandInput ,
18
18
CommandItem ,
19
19
CommandList ,
20
- CommandSeparator ,
21
- CommandShortcut
20
+ CommandSeparator
22
21
} from '@/components/ui/command'
22
+ import { useToast } from '@/components/ui/use-toast'
23
+ import { createClient } from '@/utils/supabase/client'
24
+ import { getClientUserRole } from '@/utils/supabase/getClientUserRole'
23
25
24
26
export function CommandDialogComponent ( ) {
25
- const [ open , setOpen ] = React . useState ( false )
27
+ const [ open , setOpen ] = useState ( false )
28
+ const [ userRole , setUserRole ] = useState ( '' as string )
29
+ const [ loading , setLoading ] = useState ( false )
30
+ const { toast } = useToast ( )
31
+ const [ courses , setCourses ] = useState ( [ ] )
32
+ const [ lessons , setLessons ] = useState ( [ ] )
26
33
27
- React . useEffect ( ( ) => {
34
+ useEffect ( ( ) => {
28
35
const down = ( e : KeyboardEvent ) => {
29
36
if ( e . key === 'j' && ( e . metaKey || e . ctrlKey ) ) {
30
37
e . preventDefault ( )
@@ -36,6 +43,45 @@ export function CommandDialogComponent () {
36
43
return ( ) => document . removeEventListener ( 'keydown' , down )
37
44
} , [ ] )
38
45
46
+ useEffect ( ( ) => {
47
+ async function fetchUserRole ( ) {
48
+ const response = await getClientUserRole ( )
49
+ setUserRole ( response )
50
+ }
51
+
52
+ fetchUserRole ( )
53
+ } , [ ] )
54
+
55
+ useEffect ( ( ) => {
56
+ async function fetchCourses ( ) {
57
+ setLoading ( true )
58
+ try {
59
+ const supabase = createClient ( )
60
+ const { data : courses , error } = await supabase . from ( 'courses' ) . select ( '*' ) . limit ( 5 )
61
+
62
+ if ( error ) {
63
+ console . error ( error )
64
+ return null
65
+ }
66
+
67
+ setCourses ( courses )
68
+ } catch ( error ) {
69
+ toast ( {
70
+ title : 'Error fetching courses' ,
71
+ description : error . message ,
72
+ variant : 'destructive'
73
+ } )
74
+ } finally {
75
+ setLoading ( false )
76
+ }
77
+ }
78
+
79
+ fetchCourses ( )
80
+ }
81
+ , [ userRole ] )
82
+
83
+ console . log ( courses )
84
+
39
85
return (
40
86
< >
41
87
< div className = "text-sm text-muted-foreground" >
@@ -49,8 +95,13 @@ export function CommandDialogComponent () {
49
95
< CommandEmpty > No results found.</ CommandEmpty >
50
96
< CommandGroup heading = "Suggestions" >
51
97
< CommandItem >
52
- < Calendar className = "mr-2 h-4 w-4" />
53
- < span > Calendar</ span >
98
+ < Link
99
+ className = 'flex items-center gap-2'
100
+ href = "/dashboard/notifications"
101
+ >
102
+ < Bell className = "mr-2 h-4 w-4" />
103
+ < span > Notifications</ span >
104
+ </ Link >
54
105
</ CommandItem >
55
106
< CommandItem >
56
107
< Smile className = "mr-2 h-4 w-4" />
@@ -64,21 +115,41 @@ export function CommandDialogComponent () {
64
115
< CommandSeparator />
65
116
< CommandGroup heading = "Settings" >
66
117
< CommandItem >
67
- < User className = "mr-2 h-4 w-4" />
68
- < span > Profile</ span >
69
- < CommandShortcut > ⌘P</ CommandShortcut >
70
- </ CommandItem >
71
- < CommandItem >
72
- < CreditCard className = "mr-2 h-4 w-4" />
73
- < span > Billing</ span >
74
- < CommandShortcut > ⌘B</ CommandShortcut >
118
+ < Link
119
+ className = 'flex items-center gap-2'
120
+ href = { `/dashboard/${ userRole } /profile` }
121
+ >
122
+ < User className = "mr-2 h-4 w-4" />
123
+ < span > Profile</ span >
124
+ </ Link >
75
125
</ CommandItem >
76
126
< CommandItem >
77
- < Settings className = "mr-2 h-4 w-4" />
78
- < span > Settings</ span >
79
- < CommandShortcut > ⌘S</ CommandShortcut >
127
+ < Link
128
+ className = 'flex items-center gap-2'
129
+ href = { `/dashboard/${ userRole } /profile` }
130
+ >
131
+ < CreditCard className = "mr-2 h-4 w-4" />
132
+ < span > Billing</ span >
133
+ </ Link >
80
134
</ CommandItem >
81
135
</ CommandGroup >
136
+ < CommandGroup heading = "Courses" >
137
+ { loading
138
+ ? < > Loading...</ >
139
+ : courses . map ( ( course : any ) => (
140
+ < CommandItem key = { course . course_id } >
141
+ < Link
142
+ className = 'flex items-center gap-2'
143
+ href = { `/dashboard/${ userRole } /courses/${ course . course_id } ` }
144
+ >
145
+ < span > { course . title } </ span >
146
+ </ Link >
147
+ </ CommandItem >
148
+ ) )
149
+ }
150
+
151
+ </ CommandGroup >
152
+
82
153
</ CommandList >
83
154
</ CommandDialog >
84
155
</ >
0 commit comments