@@ -14,6 +14,9 @@ import {
14
14
} from "react-icons/fi" ;
15
15
import useSWR from "swr" ;
16
16
import NavItem from "./NavItem" ;
17
+ import { useSession } from "next-auth/react" ;
18
+ import { doesUserHaveRole } from "../../utils/session" ;
19
+ import { MENTOR_ROLE , MENTEE_ROLE } from "../../constants" ;
17
20
18
21
const fetcher = ( ...args ) => fetch ( ...args ) . then ( ( res ) => res . json ( ) ) ;
19
22
@@ -27,9 +30,13 @@ const SidebarContent = ({ onClose, mode, ...rest }) => {
27
30
const requestsCount = requestsData ?. count || 0 ;
28
31
const applicationsCount = applicationsData ?. count || 0 ;
29
32
const menteesCount = menteesData ?. count || 0 ;
30
- const MentorLinkItems = [
33
+ const { data : session } = useSession ( )
34
+
35
+ const GeneralLinkItems = [
31
36
{ name : "Your profile" , icon : FiUser , href : "/profile" } ,
32
- { name : "Preferences" , icon : FiSliders , href : "/preferences" } ,
37
+ ]
38
+
39
+ const MentorLinkItems = [
33
40
{
34
41
name : "Requests" ,
35
42
icon : FiInbox ,
@@ -40,8 +47,8 @@ const SidebarContent = ({ onClose, mode, ...rest }) => {
40
47
] ;
41
48
42
49
const MenteeLinkItems = [
43
- { name : "Your profile" , icon : FiUser , href : "/profile" } ,
44
50
{ name : "Find a mentor" , icon : FiSearch , href : "/mentors" } ,
51
+ { name : "Preferences" , icon : FiSliders , href : "/preferences" } ,
45
52
{ name : "Applications" , icon : FiInbox , href : "/applications" , tag : ( ) => applicationsCount , } ,
46
53
{ name : "Mentorships" , icon : FiUsers , href : "/mentorships" , tag : ( ) => mentorshipsCount , } ,
47
54
] ;
@@ -56,6 +63,12 @@ const SidebarContent = ({ onClose, mode, ...rest }) => {
56
63
links = mode === "mentor" ? MentorLinkItems : MenteeLinkItems ;
57
64
}
58
65
66
+
67
+ // TODO: handle admins
68
+ const shouldRenderMentorLinks = profileData ?. published && doesUserHaveRole ( session , MENTOR_ROLE )
69
+
70
+ const shouldRenderMenteeLinks = profileData ?. published && doesUserHaveRole ( session , MENTEE_ROLE )
71
+
59
72
return (
60
73
< Box
61
74
transition = "3s ease"
@@ -77,7 +90,75 @@ const SidebarContent = ({ onClose, mode, ...rest }) => {
77
90
onClick = { onClose }
78
91
/>
79
92
</ Flex >
80
- < Flex h = "14" alignItems = "center" mx = "8" justifyContent = "space-between" >
93
+ < Box mt = { 50 } >
94
+ { GeneralLinkItems . map ( ( link ) => (
95
+ < NavItem
96
+ key = { link . name }
97
+ icon = { link . icon }
98
+ href = { link . href }
99
+ bg = { mode === "mentor" ? "brand.blue" : "brand.green" }
100
+ >
101
+ { link . name }
102
+ { link . tag && link . tag ( ) > 0 && (
103
+ < Tag size = "sm" colorScheme = "teal" ml = { 2 } >
104
+ { link . tag ( ) }
105
+ </ Tag >
106
+ ) }
107
+ </ NavItem >
108
+ ) ) }
109
+ </ Box >
110
+ { shouldRenderMentorLinks &&
111
+ < >
112
+ < Flex h = "14" alignItems = "center" mx = "8" justifyContent = "space-between" >
113
+ < Text textColor = "white" fontSize = "xl" fontWeight = "normal" >
114
+ Mentor
115
+ </ Text >
116
+ </ Flex >
117
+ < Box >
118
+ { MentorLinkItems . map ( ( link ) => (
119
+ < NavItem
120
+ key = { link . name }
121
+ icon = { link . icon }
122
+ href = { link . href }
123
+ bg = { mode === "mentor" ? "brand.blue" : "brand.green" }
124
+ >
125
+ { link . name }
126
+ { link . tag && link . tag ( ) > 0 && (
127
+ < Tag size = "sm" colorScheme = "teal" ml = { 2 } >
128
+ { link . tag ( ) }
129
+ </ Tag >
130
+ ) }
131
+ </ NavItem >
132
+ ) ) }
133
+ </ Box >
134
+ </ >
135
+ }
136
+ { shouldRenderMenteeLinks &&
137
+ < >
138
+ < Flex h = "14" alignItems = "center" mx = "8" justifyContent = "space-between" >
139
+ < Text textColor = "white" fontSize = "xl" fontWeight = "normal" >
140
+ Mentee
141
+ </ Text >
142
+ </ Flex >
143
+ < Box >
144
+ { MenteeLinkItems . map ( ( link ) => (
145
+ < NavItem
146
+ key = { link . name }
147
+ icon = { link . icon }
148
+ href = { link . href }
149
+ bg = { mode === "mentor" ? "brand.blue" : "brand.green" }
150
+ >
151
+ { link . name }
152
+ { link . tag && link . tag ( ) > 0 && (
153
+ < Tag size = "sm" colorScheme = "teal" ml = { 2 } >
154
+ { link . tag ( ) }
155
+ </ Tag >
156
+ ) }
157
+ </ NavItem >
158
+ ) ) }
159
+ </ Box >
160
+ </ > }
161
+ { /* <Flex h="14" alignItems="center" mx="8" justifyContent="space-between">
81
162
<Text textColor="white" fontSize="2xl" fontWeight="normal">
82
163
{mode}
83
164
</Text>
@@ -104,7 +185,7 @@ const SidebarContent = ({ onClose, mode, ...rest }) => {
104
185
tupu.io <ExternalLinkIcon mx="2px" />
105
186
</Link>
106
187
</NavItem>
107
- </ Box >
188
+ </Box> */ }
108
189
</ Box >
109
190
) ;
110
191
} ;
0 commit comments