|
1 | | -"use client"; |
| 1 | +import type { ReactNode } from "react"; |
| 2 | +import RouteProviders from "@/app/route-providers"; |
| 3 | +import AdminLayoutClient from "./admin-layout-client"; |
2 | 4 |
|
3 | | -import React, { useEffect } from "react"; |
4 | | -import { useRouter } from "next/navigation"; |
5 | | -import { useAuth } from "@/contexts/auth-context"; |
6 | | -import { AdminSidebar } from "@/components/admin/admin-sidebar"; |
7 | | -import { useTranslations } from "@/hooks/use-translations"; |
8 | | -import { |
9 | | - SidebarInset, |
10 | | - SidebarProvider, |
11 | | - SidebarTrigger, |
12 | | -} from "@/components/animate-ui/components/radix/sidebar"; |
13 | | -import { Separator } from "@/components/ui/separator"; |
14 | | -import { Loader2 } from "lucide-react"; |
| 5 | +export const dynamic = "force-dynamic"; |
15 | 6 |
|
16 | 7 | export default function AdminLayout({ |
17 | 8 | children, |
18 | 9 | }: { |
19 | | - children: React.ReactNode; |
| 10 | + children: ReactNode; |
20 | 11 | }) { |
21 | | - const router = useRouter(); |
22 | | - const { user, isLoading } = useAuth(); |
23 | | - const t = useTranslations(); |
24 | | - |
25 | | - const isAdmin = user?.roles?.includes("Admin") ?? false; |
26 | | - |
27 | | - useEffect(() => { |
28 | | - if (!isLoading && !isAdmin) { |
29 | | - router.push("/"); |
30 | | - } |
31 | | - }, [isAdmin, isLoading, router]); |
32 | | - |
33 | | - if (isLoading) { |
34 | | - return ( |
35 | | - <div className="flex h-screen items-center justify-center"> |
36 | | - <Loader2 className="h-8 w-8 animate-spin text-muted-foreground" /> |
37 | | - </div> |
38 | | - ); |
39 | | - } |
40 | | - |
41 | | - if (!isAdmin) { |
42 | | - return null; |
43 | | - } |
44 | | - |
45 | 12 | return ( |
46 | | - <SidebarProvider defaultOpen={true}> |
47 | | - <AdminSidebar /> |
48 | | - <SidebarInset> |
49 | | - <header className="sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 border-b bg-background/95 px-4 backdrop-blur supports-[backdrop-filter]:bg-background/60"> |
50 | | - <SidebarTrigger className="-ml-1" /> |
51 | | - <Separator orientation="vertical" className="mr-2 h-4" /> |
52 | | - <h1 className="text-sm font-semibold">{t("common.adminPanel")}</h1> |
53 | | - </header> |
54 | | - <main className="flex-1 overflow-auto"> |
55 | | - <div className="container mx-auto p-6"> |
56 | | - {children} |
57 | | - </div> |
58 | | - </main> |
59 | | - </SidebarInset> |
60 | | - </SidebarProvider> |
| 13 | + <RouteProviders> |
| 14 | + <AdminLayoutClient>{children}</AdminLayoutClient> |
| 15 | + </RouteProviders> |
61 | 16 | ); |
62 | 17 | } |
0 commit comments