Add platform settings (Stage 9)
- Settings key-value table in Prisma with migration - getSettings() / getSetting() helpers in lib/settings.ts - Admin UI at /admin/settings with 6 sections: General, Notifications, Student profile, Legal docs, Curator permissions, Code injection - saveSettings() server action with admin-only guard - Maintenance mode: non-admin users redirected to /maintenance page - schoolName propagated to page metadata and all email templates - headCode / bodyCode injected into root layout <head> and <body> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"use server";
|
||||
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { SETTINGS_DEFAULTS, type SettingsKey } from "@/lib/settings";
|
||||
|
||||
export async function saveSettings(data: Record<string, string>) {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session || session.user.role !== "admin") throw new Error("Нет доступа");
|
||||
|
||||
const validKeys = Object.keys(SETTINGS_DEFAULTS) as SettingsKey[];
|
||||
const ops = validKeys
|
||||
.filter((key) => key in data)
|
||||
.map((key) =>
|
||||
prisma.settings.upsert({
|
||||
where: { key },
|
||||
update: { value: data[key] },
|
||||
create: { key, value: data[key] },
|
||||
})
|
||||
);
|
||||
|
||||
await Promise.all(ops);
|
||||
revalidatePath("/admin/settings");
|
||||
revalidatePath("/", "layout");
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { getSettings } from "@/lib/settings";
|
||||
import { SettingsForm } from "@/components/admin/settings-form";
|
||||
|
||||
export const metadata = { title: "Настройки платформы" };
|
||||
|
||||
export default async function SettingsPage() {
|
||||
const settings = await getSettings();
|
||||
|
||||
return (
|
||||
<div className="p-8 max-w-2xl">
|
||||
<div className="mb-6">
|
||||
<h1
|
||||
className="text-xs font-bold uppercase tracking-widest"
|
||||
style={{ color: "var(--muted-foreground)" }}
|
||||
>
|
||||
Настройки платформы
|
||||
</h1>
|
||||
</div>
|
||||
<SettingsForm initial={settings} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user