@@ -6,7 +6,7 @@ import { useParams } from 'next/navigation'
66import { Button } from '@/components/ui/button'
77import { CompanySidebar } from '@/components/dashboard/CompanySidebar'
88import { CompanyHeader } from '@/components/dashboard/CompanyHeader'
9- import { CompanyProvider } from '@/contexts/CompanyContext'
9+ import { CompanyProvider , useCompanyContext } from '@/contexts/CompanyContext'
1010import {
1111 LayoutDashboard ,
1212 Calendar ,
@@ -110,6 +110,7 @@ export default function CompanyDashboardLayout({
110110 )
111111}
112112
113+ // Component that uses CompanyContext to conditionally render sidebar
113114function CompanyDashboardContent ( {
114115 avatar,
115116 name,
@@ -123,6 +124,21 @@ function CompanyDashboardContent({
123124} ) {
124125 const params = useParams ( )
125126 const companySlug = params ?. slug as string
127+ const { currentCompany, loading, error } = useCompanyContext ( )
128+
129+ // Show loading while company context is loading
130+ if ( loading ) {
131+ return (
132+ < div className = "flex items-center justify-center min-h-screen bg-black" >
133+ < div className = "animate-spin rounded-full h-8 w-8 border-b-2 border-primary" > </ div >
134+ </ div >
135+ )
136+ }
137+
138+ // If no company access (error or no currentCompany), don't render sidebar
139+ if ( error || ! currentCompany ) {
140+ return < div className = "bg-black min-h-screen w-full" > { children } </ div >
141+ }
126142
127143 // Generate sidebar items with dynamic company slug
128144 const sidebarItems : SidebarGroupType [ ] = [
0 commit comments