1- import { AppSidebar } from '@/components/app-sidebar ' ;
1+ import { AnimatedLayout } from '@/components/animated-layout ' ;
22import { CheckoutCompleteDialog } from '@/components/dialogs/checkout-complete-dialog' ;
33import { Header } from '@/components/header' ;
44import { AssistantSheet } from '@/components/sheets/assistant-sheet' ;
5+ import { Sidebar } from '@/components/sidebar' ;
56import { TriggerTokenProvider } from '@/components/trigger-token-provider' ;
7+ import { SidebarProvider } from '@/context/sidebar-context' ;
68import { auth } from '@/utils/auth' ;
7- import { SidebarInset , SidebarProvider } from '@comp/ui/sidebar' ;
89import { db , Role } from '@db' ;
910import dynamic from 'next/dynamic' ;
1011import { cookies , headers } from 'next/headers' ;
@@ -14,6 +15,7 @@ import { ConditionalOnboardingTracker } from './components/ConditionalOnboarding
1415import { ConditionalPaddingWrapper } from './components/ConditionalPaddingWrapper' ;
1516import { DynamicMinHeight } from './components/DynamicMinHeight' ;
1617
18+ // Helper to safely parse comma-separated roles string
1719function parseRolesString ( rolesStr : string | null | undefined ) : Role [ ] {
1820 if ( ! rolesStr ) return [ ] ;
1921 return rolesStr
@@ -36,9 +38,10 @@ export default async function Layout({
3638 const { orgId : requestedOrgId } = await params ;
3739
3840 const cookieStore = await cookies ( ) ;
39- const defaultOpen = cookieStore . get ( 'sidebar_state ' ) ?. value !== 'false ';
40- const publicAccessToken = cookieStore . get ( 'publicAccessToken' ) ?. value || undefined ;
41+ const isCollapsed = cookieStore . get ( 'sidebar-collapsed ' ) ?. value === 'true ';
42+ let publicAccessToken = cookieStore . get ( 'publicAccessToken' ) ?. value || undefined ;
4143
44+ // Check if user has access to this organization
4245 const session = await auth . api . getSession ( {
4346 headers : await headers ( ) ,
4447 } ) ;
@@ -48,11 +51,13 @@ export default async function Layout({
4851 return redirect ( '/auth' ) ;
4952 }
5053
54+ // First check if the organization exists and load access flags
5155 const organization = await db . organization . findUnique ( {
5256 where : { id : requestedOrgId } ,
5357 } ) ;
5458
5559 if ( ! organization ) {
60+ // Organization doesn't exist
5661 return redirect ( '/auth/not-found' ) ;
5762 }
5863
@@ -65,6 +70,7 @@ export default async function Layout({
6570 } ) ;
6671
6772 if ( ! member ) {
73+ // User doesn't have access to this organization
6874 return redirect ( '/auth/unauthorized' ) ;
6975 }
7076
@@ -76,10 +82,12 @@ export default async function Layout({
7682 return redirect ( '/no-access' ) ;
7783 }
7884
85+ // If this org is not accessible on current plan, redirect to upgrade
7986 if ( ! organization . hasAccess ) {
8087 return redirect ( `/upgrade/${ organization . id } ` ) ;
8188 }
8289
90+ // If onboarding is required and user isn't already on onboarding, redirect
8391 if ( ! organization . onboardingCompleted ) {
8492 return redirect ( `/onboarding/${ organization . id } ` ) ;
8593 }
@@ -95,9 +103,8 @@ export default async function Layout({
95103 triggerJobId = { onboarding ?. triggerJobId || undefined }
96104 initialToken = { publicAccessToken || undefined }
97105 >
98- < SidebarProvider defaultOpen = { defaultOpen } >
99- < AppSidebar organization = { organization } />
100- < SidebarInset >
106+ < SidebarProvider initialIsCollapsed = { isCollapsed } >
107+ < AnimatedLayout sidebar = { < Sidebar organization = { organization } /> } isCollapsed = { isCollapsed } >
101108 { onboarding ?. triggerJobId && < ConditionalOnboardingTracker onboarding = { onboarding } /> }
102109 < Header organizationId = { organization . id } />
103110 < ConditionalPaddingWrapper >
@@ -107,7 +114,7 @@ export default async function Layout({
107114 < Suspense fallback = { null } >
108115 < CheckoutCompleteDialog orgId = { organization . id } />
109116 </ Suspense >
110- </ SidebarInset >
117+ </ AnimatedLayout >
111118 < HotKeys />
112119 </ SidebarProvider >
113120 </ TriggerTokenProvider >
0 commit comments