1
1
"use client" ;
2
2
3
3
import { useI18n } from "@/locales/client" ;
4
+ import { authClient } from "@/utils/auth-client" ;
4
5
import { Badge } from "@comp/ui/badge" ;
5
6
import { cn } from "@comp/ui/cn" ;
6
7
import { Icons } from "@comp/ui/icons" ;
@@ -45,23 +46,24 @@ type MenuItem = {
45
46
} ;
46
47
47
48
interface ItemProps {
49
+ organizationId : string ;
48
50
item : MenuItem ;
49
51
isActive : boolean ;
50
52
disabled : boolean ;
51
- organizationId : string ;
52
53
isCollapsed ?: boolean ;
53
54
onItemClick ?: ( ) => void ;
54
55
}
55
56
56
57
export function MainMenu ( {
57
- organizationId,
58
58
//userIsAdmin,
59
59
isCollapsed = false ,
60
60
completedOnboarding,
61
61
onItemClick,
62
62
} : Props ) {
63
63
const t = useI18n ( ) ;
64
64
const pathname = usePathname ( ) ;
65
+ const session = authClient . useSession ( ) ;
66
+ const organizationId = session ?. data ?. session ?. activeOrganizationId ;
65
67
66
68
const items : MenuItem [ ] = [
67
69
{
@@ -167,12 +169,13 @@ export function MainMenu({
167
169
const isPathActive = ( itemPath : string ) => {
168
170
const normalizedItemPath = itemPath . replace (
169
171
":organizationId" ,
170
- organizationId ,
172
+ organizationId ?? "" ,
171
173
) ;
172
174
173
175
// Extract the base path from the menu item (first two segments after normalization)
174
176
const itemPathParts = normalizedItemPath . split ( "/" ) . filter ( Boolean ) ;
175
- const itemBaseSegment = itemPathParts . length > 1 ? itemPathParts [ 1 ] : "" ;
177
+ const itemBaseSegment =
178
+ itemPathParts . length > 1 ? itemPathParts [ 1 ] : "" ;
176
179
177
180
// Extract the current path parts
178
181
const currentPathParts = pathname . split ( "/" ) . filter ( Boolean ) ;
@@ -232,10 +235,10 @@ export function MainMenu({
232
235
return (
233
236
< Item
234
237
key = { item . id }
238
+ organizationId = { organizationId ?? "" }
235
239
item = { item }
236
240
isActive = { isActive }
237
241
disabled = { item . disabled }
238
- organizationId = { organizationId }
239
242
isCollapsed = { isCollapsed }
240
243
onItemClick = { onItemClick }
241
244
/>
@@ -248,10 +251,10 @@ export function MainMenu({
248
251
}
249
252
250
253
const Item = ( {
254
+ organizationId,
251
255
item,
252
256
isActive,
253
257
disabled,
254
- organizationId,
255
258
isCollapsed = false ,
256
259
onItemClick,
257
260
} : ItemProps ) => {
@@ -265,7 +268,8 @@ const Item = ({
265
268
// Badge variants mapping
266
269
const badgeVariants = {
267
270
default : "bg-primary/80 text-primary-foreground hover:bg-primary/90" ,
268
- secondary : "bg-secondary text-secondary-foreground hover:bg-secondary/80" ,
271
+ secondary :
272
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80" ,
269
273
outline :
270
274
"border-border bg-background hover:bg-accent hover:text-accent-foreground" ,
271
275
new : "bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400" ,
@@ -285,12 +289,14 @@ const Item = ({
285
289
< div
286
290
className = { cn (
287
291
"relative border border-transparent flex items-center" ,
288
- isCollapsed ? "md:w-[45px] md:justify-center" : "md:px-3" ,
292
+ isCollapsed
293
+ ? "md:w-[45px] md:justify-center"
294
+ : "md:px-3" ,
289
295
"w-full px-3 md:w-auto h-[45px]" ,
290
296
"hover:bg-accent hover:border-border" ,
291
297
"transition-all duration-300" ,
292
298
isActive &&
293
- "bg-accent dark:bg-secondary border-border border-r-2 border-r-primary" ,
299
+ "bg-accent dark:bg-secondary border-border border-r-2 border-r-primary" ,
294
300
) }
295
301
>
296
302
< div
@@ -316,7 +322,10 @@ const Item = ({
316
322
variant = "outline"
317
323
className = { cn (
318
324
"ml-1.5 text-[9px] px-1 py-0 h-auto" ,
319
- badgeVariants [ item . badge . variant ] ,
325
+ badgeVariants [
326
+ item . badge
327
+ . variant
328
+ ] ,
320
329
) }
321
330
>
322
331
{ item . badge . text }
@@ -362,9 +371,8 @@ const Item = ({
362
371
} ;
363
372
364
373
type Props = {
365
- organizationId : string ;
366
374
//userIsAdmin: boolean;
367
375
isCollapsed ?: boolean ;
368
376
completedOnboarding : boolean ;
369
377
onItemClick ?: ( ) => void ;
370
- } ;
378
+ } ;
0 commit comments