Skip to content

Commit f1b7ee9

Browse files
committed
feat(dashboard): Add company context integration and loading states
- Import useCompanyContext hook to access company context state - Add loading state handling with spinner animation during context initialization - Add error state handling to conditionally render sidebar based on company access - Implement conditional rendering logic to hide sidebar when company context is unavailable - Add explanatory comment for CompanyDashboardContent component purpose - Improve user experience by showing loading indicator while company data is being fetched
1 parent eafcbad commit f1b7ee9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

app/dashboard/company/layout.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useParams } from 'next/navigation'
66
import { Button } from '@/components/ui/button'
77
import { CompanySidebar } from '@/components/dashboard/CompanySidebar'
88
import { CompanyHeader } from '@/components/dashboard/CompanyHeader'
9-
import { CompanyProvider } from '@/contexts/CompanyContext'
9+
import { CompanyProvider, useCompanyContext } from '@/contexts/CompanyContext'
1010
import {
1111
LayoutDashboard,
1212
Calendar,
@@ -110,6 +110,7 @@ export default function CompanyDashboardLayout({
110110
)
111111
}
112112

113+
// Component that uses CompanyContext to conditionally render sidebar
113114
function 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

Comments
 (0)