/news and six admin pages issued raw prisma reads with no try/catch, so a DB outage rendered a 500 instead of an empty state. Wrap each read (try/catch or .catch(() => fallback), preserving select() row types and notFound() on the user-detail page). Matches the fail-soft pattern used across the rest of the app. Verified: tsc 0, next build 0, all public pages 200 against a dead DB.
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import { createSetting, deleteSetting, updateSetting } from "@/actions/admin-settings";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminSettings() {
|
|
let settings: Awaited<ReturnType<typeof prisma.websiteSetting.findMany>> = [];
|
|
try {
|
|
settings = await prisma.websiteSetting.findMany({ orderBy: { key: "asc" } });
|
|
} catch {
|
|
settings = [];
|
|
}
|
|
|
|
return (
|
|
<main>
|
|
<h1>CMS Settings</h1>
|
|
<p className="muted">
|
|
Key/value config read at runtime via <code>siteSettings.get()</code>. Saving busts the cache.
|
|
</p>
|
|
|
|
<form action={createSetting} className="card" style={{ marginBottom: "1.5rem" }}>
|
|
<h3 style={{ marginTop: 0 }}>Add / overwrite</h3>
|
|
<div style={{ display: "flex", gap: "0.5rem", flexWrap: "wrap" }}>
|
|
<input name="key" placeholder="key" required />
|
|
<input name="value" placeholder="value" style={{ flex: 1, minWidth: 160 }} />
|
|
<input name="comment" placeholder="comment" />
|
|
<button type="submit">Save</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div className="grid">
|
|
{settings.map((s) => (
|
|
<div key={s.key} className="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">Save</button>
|
|
</form>
|
|
<form action={deleteSetting}>
|
|
<input type="hidden" name="key" value={s.key} />
|
|
<button type="submit">✕</button>
|
|
</form>
|
|
</div>
|
|
{s.comment ? (
|
|
<p className="muted" style={{ margin: "0.4rem 0 0" }}>
|
|
{s.comment}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
))}
|
|
</div>
|
|
{settings.length === 0 ? <p className="muted">No settings yet.</p> : null}
|
|
</main>
|
|
);
|
|
}
|