2026-04-09 10:01:23 +08:00
|
|
|
"use client"
|
|
|
|
|
|
2026-04-19 20:30:41 +08:00
|
|
|
import { Loader2Icon } from "lucide-react"
|
2026-04-24 11:35:29 +08:00
|
|
|
import { usePathname, useRouter } from "next/navigation"
|
2026-04-19 20:30:41 +08:00
|
|
|
import type { CSSProperties, ReactNode } from "react"
|
2026-04-09 10:01:23 +08:00
|
|
|
import { useEffect } from "react"
|
|
|
|
|
|
|
|
|
|
import { AppSidebar } from "@/components/app-sidebar"
|
|
|
|
|
import { useAuth } from "@/components/auth-provider"
|
2026-04-28 19:20:38 +08:00
|
|
|
import { NotificationProvider } from "@/components/notification-provider"
|
2026-04-09 10:01:23 +08:00
|
|
|
import { SiteHeader } from "@/components/site-header"
|
2026-05-25 12:06:15 +08:00
|
|
|
import { useI18n } from "@/i18n/provider"
|
2026-04-09 10:01:23 +08:00
|
|
|
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"
|
|
|
|
|
|
|
|
|
|
export default function DashboardLayout({
|
|
|
|
|
children,
|
|
|
|
|
}: {
|
|
|
|
|
children: ReactNode
|
|
|
|
|
}) {
|
2026-05-25 12:06:15 +08:00
|
|
|
const t = useI18n()
|
2026-04-09 10:01:23 +08:00
|
|
|
const { ready, session } = useAuth()
|
2026-04-24 11:35:29 +08:00
|
|
|
const pathname = usePathname()
|
2026-04-09 10:01:23 +08:00
|
|
|
const router = useRouter()
|
2026-04-24 11:35:29 +08:00
|
|
|
const isLoginRoute = pathname?.startsWith("/dashboard/login") ?? false
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-04-24 11:35:29 +08:00
|
|
|
if (ready && !session && !isLoginRoute) {
|
|
|
|
|
router.replace("/dashboard/login")
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-04-24 11:35:29 +08:00
|
|
|
}, [isLoginRoute, ready, router, session])
|
|
|
|
|
|
|
|
|
|
if (isLoginRoute) {
|
|
|
|
|
return <>{children}</>
|
|
|
|
|
}
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
if (!ready || !session) {
|
|
|
|
|
return (
|
2026-06-21 10:09:52 +08:00
|
|
|
<div className="flex min-h-screen items-center justify-center bg-background p-6">
|
2026-04-19 20:30:41 +08:00
|
|
|
<div className="flex items-center gap-3">
|
2026-06-21 10:09:52 +08:00
|
|
|
<div className="flex size-10 items-center justify-center rounded-md bg-muted text-muted-foreground">
|
2026-04-19 20:30:41 +08:00
|
|
|
<Loader2Icon className="size-5 animate-spin" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-1">
|
2026-05-25 12:06:15 +08:00
|
|
|
<p className="text-base font-medium">{t("auth.checkingSession")}</p>
|
2026-04-19 20:30:41 +08:00
|
|
|
<p className="text-sm text-muted-foreground">
|
2026-05-25 12:06:15 +08:00
|
|
|
{t("auth.syncingProfile")}
|
2026-04-19 20:30:41 +08:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-04-09 10:01:23 +08:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SidebarProvider
|
2026-04-29 10:40:09 +08:00
|
|
|
className="h-svh min-h-0 overflow-hidden"
|
2026-04-09 10:01:23 +08:00
|
|
|
style={
|
|
|
|
|
{
|
|
|
|
|
"--sidebar-width": "calc(var(--spacing) * 54)",
|
|
|
|
|
"--header-height": "calc(var(--spacing) * 12)",
|
|
|
|
|
} as CSSProperties
|
|
|
|
|
}
|
|
|
|
|
>
|
2026-04-28 19:20:38 +08:00
|
|
|
<NotificationProvider>
|
|
|
|
|
<AppSidebar variant="inset" />
|
2026-06-21 10:09:52 +08:00
|
|
|
<SidebarInset className="overflow-hidden border-l border-border/70 bg-background">
|
2026-04-28 19:20:38 +08:00
|
|
|
<SiteHeader />
|
2026-06-21 10:09:52 +08:00
|
|
|
<div className="@container/main flex min-h-0 flex-1 flex-col overflow-auto">
|
2026-05-06 21:03:15 +08:00
|
|
|
{children}
|
2026-04-09 10:01:23 +08:00
|
|
|
</div>
|
2026-04-28 19:20:38 +08:00
|
|
|
</SidebarInset>
|
|
|
|
|
</NotificationProvider>
|
2026-04-09 10:01:23 +08:00
|
|
|
</SidebarProvider>
|
|
|
|
|
)
|
|
|
|
|
}
|