45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { redirect } from "next/navigation";
|
||
|
||
import { getActiveContext } from "@/lib/appwrite/active-context";
|
||
import { getLogoUrl } from "@/lib/appwrite/storage";
|
||
import { createSessionClient } from "@/lib/appwrite/server";
|
||
import type { ThemePrefs } from "@/lib/appwrite/theme-prefs-actions";
|
||
import { DashboardShell } from "./dashboard-shell";
|
||
|
||
export default async function DashboardLayout({
|
||
children,
|
||
}: {
|
||
children: React.ReactNode;
|
||
}) {
|
||
const ctx = await getActiveContext();
|
||
if (!ctx) redirect("/onboarding");
|
||
|
||
let themePrefs: ThemePrefs = {};
|
||
try {
|
||
const { account } = await createSessionClient();
|
||
const raw = await account.getPrefs<ThemePrefs>();
|
||
// getPrefs returns an Appwrite prototype object — serialize to plain object
|
||
// so Next.js can pass it from Server → Client Component
|
||
themePrefs = JSON.parse(JSON.stringify(raw)) as ThemePrefs;
|
||
} catch {
|
||
// use defaults if prefs unavailable
|
||
}
|
||
|
||
const company = {
|
||
id: ctx.tenantId,
|
||
name: ctx.settings?.officeName ?? "Çalışma alanı",
|
||
logoUrl: getLogoUrl(ctx.settings?.logo) ?? null,
|
||
};
|
||
const user = {
|
||
id: ctx.user.id,
|
||
name: ctx.user.name || ctx.user.email,
|
||
email: ctx.user.email,
|
||
};
|
||
|
||
return (
|
||
<DashboardShell user={user} company={company} initialPrefs={themePrefs}>
|
||
{children}
|
||
</DashboardShell>
|
||
);
|
||
}
|