From f1b7ee9bb9e7b745ef1b7ea8f8db5f63289ea6d7 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 15 Nov 2025 13:57:16 +0530 Subject: [PATCH] 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 --- app/dashboard/company/layout.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/dashboard/company/layout.tsx b/app/dashboard/company/layout.tsx index a799fbe3..690a6e6a 100644 --- a/app/dashboard/company/layout.tsx +++ b/app/dashboard/company/layout.tsx @@ -6,7 +6,7 @@ import { useParams } from 'next/navigation' import { Button } from '@/components/ui/button' import { CompanySidebar } from '@/components/dashboard/CompanySidebar' import { CompanyHeader } from '@/components/dashboard/CompanyHeader' -import { CompanyProvider } from '@/contexts/CompanyContext' +import { CompanyProvider, useCompanyContext } from '@/contexts/CompanyContext' import { LayoutDashboard, Calendar, @@ -110,6 +110,7 @@ export default function CompanyDashboardLayout({ ) } +// Component that uses CompanyContext to conditionally render sidebar function CompanyDashboardContent({ avatar, name, @@ -123,6 +124,21 @@ function CompanyDashboardContent({ }) { const params = useParams() const companySlug = params?.slug as string + const { currentCompany, loading, error } = useCompanyContext() + + // Show loading while company context is loading + if (loading) { + return ( +
+
+
+ ) + } + + // If no company access (error or no currentCompany), don't render sidebar + if (error || !currentCompany) { + return
{children}
+ } // Generate sidebar items with dynamic company slug const sidebarItems: SidebarGroupType[] = [