mirror of
https://git.coastit.co.za/caitlin/CRM_ENVR.git
synced 2026-07-10 11:15:43 +02:00
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect } from "react"
|
|
import { useRouter } from "next/navigation"
|
|
import { AppShell } from "@/components/layout/app-shell"
|
|
import { UserProvider, useUser } from "@/providers/user-provider"
|
|
import { NotificationProvider } from "@/providers/notification-provider"
|
|
import { ErrorBoundary } from "@/components/shared/error-boundary"
|
|
import { Loader2 } from "lucide-react"
|
|
|
|
function DashboardContent({ children }: { children: React.ReactNode }) {
|
|
const { user, loading } = useUser()
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
if (!user && !loading) {
|
|
router.push("/login")
|
|
}
|
|
}, [user, loading, router])
|
|
|
|
if (loading || !user) {
|
|
return (
|
|
<div className="flex h-screen items-center justify-center">
|
|
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return <AppShell>{children}</AppShell>
|
|
}
|
|
|
|
export default function DashboardLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode
|
|
}) {
|
|
return (
|
|
<UserProvider>
|
|
<NotificationProvider>
|
|
<ErrorBoundary>
|
|
<DashboardContent>{children}</DashboardContent>
|
|
</ErrorBoundary>
|
|
</NotificationProvider>
|
|
</UserProvider>
|
|
)
|
|
}
|