Fix rooms list crash and rebuild CMS settings UI.
Rooms queried the wrong Prisma model and a non-existent owner relation. Settings now use grouped managed fields plus a searchable advanced key/value panel. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
c186f51ae0
commit
e101ea474e
6 files changed
+796
-104
No files matched your search
@@ -1,22 +1,32 @@
|
||||
import { Cog, ExternalLink } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import {
|
||||
createSetting,
|
||||
deleteSetting,
|
||||
updateSetting,
|
||||
} from "@/actions/admin-settings";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { AdvancedSettingsPanel } from "./advanced-settings-panel";
|
||||
import { FIELD_DEFAULTS, MANAGED_SETTING_KEYS } from "./cms-settings-config";
|
||||
import { CmsSettingsForm } from "./cms-settings-form";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const metadata = { title: "CMS Settings" };
|
||||
|
||||
const RELATED = [
|
||||
{ href: "/admin/theme", label: "Theme & colors" },
|
||||
{ href: "/admin/maintenance", label: "Maintenance" },
|
||||
{ href: "/admin/vpn", label: "VPN / proxy block" },
|
||||
{ href: "/admin/emulator", label: "Emulator config" },
|
||||
] as const;
|
||||
|
||||
export default async function AdminSettings() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.SETTINGS_VIEW, session.user.rank)) {
|
||||
redirect("/admin");
|
||||
}
|
||||
|
||||
const t = await getTranslations("pages.admin.settings");
|
||||
const canEdit = canAccess(
|
||||
permissions,
|
||||
PERMS.SETTINGS_EDIT,
|
||||
session.user.rank,
|
||||
);
|
||||
|
||||
let settings: Awaited<ReturnType<typeof prisma.websiteSetting.findMany>> = [];
|
||||
try {
|
||||
@@ -27,103 +37,66 @@ export default async function AdminSettings() {
|
||||
settings = [];
|
||||
}
|
||||
|
||||
const dbValues = new Map(settings.map((s) => [s.key, s.value]));
|
||||
const values: Record<string, string> = Object.fromEntries(
|
||||
MANAGED_SETTING_KEYS.map((key) => [
|
||||
key,
|
||||
dbValues.get(key) ?? FIELD_DEFAULTS[key] ?? "",
|
||||
]),
|
||||
);
|
||||
|
||||
const documented = settings.filter((s) => !!s.comment).length;
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div className="flex items-center gap-3 mb-6">
|
||||
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-[var(--admin-accent)]/20 to-[var(--admin-accent)]/5 grid place-items-center">
|
||||
<span className="text-lg">⚙️</span>
|
||||
<div className="space-y-8">
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-[var(--admin-accent)]/20 to-[var(--admin-accent)]/5 grid place-items-center">
|
||||
<Cog size={20} className="text-[var(--admin-accent)]" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="m-0 text-2xl font-extrabold tracking-tight text-[var(--admin-text)]">
|
||||
CMS Settings
|
||||
</h1>
|
||||
<p className="m-0 mt-0.5 text-sm text-[var(--admin-text-muted)]">
|
||||
Configure hotel identity, imaging, client, radio and security.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="m-0 text-xl font-extrabold text-[var(--admin-text)]">
|
||||
{t("title")}
|
||||
</h1>
|
||||
<p className="m-0 text-xs text-[var(--admin-text-muted)] mt-0.5">
|
||||
{t.rich("subtitle", { code: (chunks) => <code>{chunks}</code> })}
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{RELATED.map((item) => (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className="inline-flex items-center gap-1.5 rounded-full border border-[var(--admin-border)] bg-[var(--admin-surface)] px-3 py-1.5 text-xs font-semibold text-[var(--admin-text)] no-underline hover:border-[var(--admin-accent)] transition-colors"
|
||||
>
|
||||
{item.label}
|
||||
<ExternalLink size={12} className="opacity-60" />
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="admin-stat-row">
|
||||
<span className="admin-stat-chip">
|
||||
{t("settingsCount", { count: settings.length })}
|
||||
{settings.length} keys in database
|
||||
</span>
|
||||
<span className="admin-stat-chip">
|
||||
{t("documentedCount", { count: documented })}
|
||||
{MANAGED_SETTING_KEYS.length} managed in form
|
||||
</span>
|
||||
<span className="admin-stat-chip">{documented} documented</span>
|
||||
</div>
|
||||
|
||||
<section>
|
||||
<h2 className="admin-section-title">{t("addOverwrite")}</h2>
|
||||
<form action={createSetting} className="admin-card">
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
<input name="key" placeholder={t("form.keyPlaceholder")} required />
|
||||
<input
|
||||
name="value"
|
||||
placeholder={t("form.valuePlaceholder")}
|
||||
className="flex-1 min-w-[160px]"
|
||||
/>
|
||||
<input name="comment" placeholder={t("form.commentPlaceholder")} />
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("save")}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<CmsSettingsForm values={values} canEdit={canEdit} />
|
||||
|
||||
<section>
|
||||
<h2 className="admin-section-title">
|
||||
{t("settings")}{" "}
|
||||
<span className="inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full bg-[var(--admin-accent)]/18 text-[var(--admin-text)]">
|
||||
{settings.length}
|
||||
</span>
|
||||
</h2>
|
||||
{settings.length === 0 ? (
|
||||
<div className="admin-empty">{t("noSettings")}</div>
|
||||
) : (
|
||||
<div className="grid">
|
||||
{settings.map((s) => (
|
||||
<div key={s.key} className="admin-card">
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "0.75rem",
|
||||
alignItems: "baseline",
|
||||
}}
|
||||
>
|
||||
<strong style={{ minWidth: 220 }}>{s.key}</strong>
|
||||
<form
|
||||
action={updateSetting}
|
||||
style={{ display: "flex", gap: "0.5rem", flex: 1 }}
|
||||
>
|
||||
<input type="hidden" name="key" value={s.key} />
|
||||
<input
|
||||
name="value"
|
||||
defaultValue={s.value}
|
||||
style={{ flex: 1 }}
|
||||
/>
|
||||
<button type="submit" className="btn btn-outline">
|
||||
{t("save")}
|
||||
</button>
|
||||
</form>
|
||||
<form action={deleteSetting}>
|
||||
<input type="hidden" name="key" value={s.key} />
|
||||
<button type="submit" className="btn btn-danger">
|
||||
✕
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{s.comment ? (
|
||||
<p className="muted" style={{ margin: "0.4rem 0 0" }}>
|
||||
{s.comment}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
<AdvancedSettingsPanel
|
||||
settings={settings.map((s) => ({
|
||||
key: s.key,
|
||||
value: s.value,
|
||||
comment: s.comment,
|
||||
}))}
|
||||
canEdit={canEdit}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user