Files
Epicnabbo-Catalogus-Updated…/src/app/admin/emulator/page.tsx
T
openhands 1acace49d0 refactor: full codebase overhaul — dead code removal, env validation, logger migration, date consolidation, Prisma schema cleanup, button consistency, useEffect deps, test coverage
- env.ts: added 10 missing Zod-validated env vars (imager, paypal currency, argon2/bcrypt params)
- Migrated 6 modules from process.env to validated env.* (auth, proxy-auth, paypal, password, redis, imager, moderation, alert, logger)
- Replaced console.warn/error with pino logger in 9 server-side modules
- Removed 50+ dead exports (SWF wrappers, coalesceHotelName, signIn, isStaff re-export, formatTimestamp, Skeleton/SkeletonCard, 4 unused housekeeping sections)
- Consolidated date formatting: 28 files migrated to shared formatDate() from @/lib/format-date
- Wired 4 radio/settings API routes through cached siteSettings service instead of raw Prisma queries
- Added getMany()/getAll() helpers to SiteSettings service
- Removed 88 dead Prisma model definitions (schema 2763→1846 lines)
- Created admin action-helper.ts with wrapAction() for standardized error handling
- Fixed useEffect dependency arrays in 4 data-heavy components
- Replaced raw btn CSS classes with shadcn Button component across admin pages
- Stripped dead i18n namespaces (common, pages.client) from all 22 translation files
- Removed 2 dead scripts (create-release.sh, check-local-imports.ts)
- Fixed knip.json configuration
- Added 7 new test suites: format-date, paypal, moderation, alert, webhook, action-helper, and fixed password.test.ts for env mocking
- All 358 tests passing across 72 test files
- TypeScript: 0 errors
2026-07-25 17:33:06 +02:00

195 lines
5.0 KiB
TypeScript

import { redirect } from "next/navigation";
import { getTranslations } from "next-intl/server";
import {
updateEmulatorSetting,
updateEmulatorText,
} from "@/actions/admin-emulator";
import { StatusCard } from "@/components/admin/dashboard";
import { Button } from "@/components/ui/button";
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
const TEXTS_LIMIT = 300;
export default async function AdminEmulator() {
const { session, permissions } = await getAdminContext();
if (!canAccess(permissions, PERMS.SETTINGS_VIEW, session.user.rank)) {
redirect("/admin");
}
const t = await getTranslations("pages.admin.emulator");
let settings: { key: string; value: string }[] = [];
try {
settings = await prisma.emulatorSettings.findMany({
orderBy: { key: "asc" },
});
} catch {
settings = [];
}
let texts: { key: string; value: string }[] = [];
let textsCount = 0;
try {
textsCount = await prisma.emulatorTexts.count();
} catch {
textsCount = 0;
}
try {
texts = await prisma.emulatorTexts.findMany({
orderBy: { key: "asc" },
take: TEXTS_LIMIT,
});
} catch {
texts = [];
}
const textsTruncated = textsCount > texts.length;
return (
<main>
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
<StatusCard
label={t("settingsKeys")}
value={settings.length}
icon="⚙️"
/>
<StatusCard label={t("textKeys")} value={textsCount} icon="🗒️" />
</div>
<section className="mt-6">
<h2 className="admin-section-title">{t("settings")}</h2>
<p className="text-xs theme-text-muted dark:theme-text-muted mb-3">
{t("keysCount", { count: settings.length })}
</p>
<form action={updateEmulatorSetting} className="admin-card mb-6">
<h3 className="text-sm font-bold text-[var(--admin-text)] m-0 mb-3">
{t("addOverwriteSetting")}
</h3>
<div className="flex gap-2 flex-wrap">
<input name="key" placeholder={t("key")} maxLength={100} required />
<input
name="value"
placeholder={t("value")}
maxLength={512}
className="flex-1 min-w-[200px]"
/>
<Button type="submit" variant="default">
{t("save")}
</Button>
</div>
</form>
<table>
<thead>
<tr>
<th className="w-[320px]">{t("colKey")}</th>
<th>{t("colValue")}</th>
</tr>
</thead>
<tbody>
{settings.map((s) => (
<tr key={s.key}>
<td>
<strong>{s.key}</strong>
</td>
<td>
<form action={updateEmulatorSetting} className="flex gap-2">
<input type="hidden" name="key" value={s.key} />
<input
name="value"
defaultValue={s.value}
maxLength={512}
className="flex-1"
/>
<Button type="submit" variant="outline">
{t("save")}
</Button>
</form>
</td>
</tr>
))}
</tbody>
</table>
{settings.length === 0 ? (
<p className="text-xs theme-text-muted dark:theme-text-muted">
{t("noSettings")}
</p>
) : null}
</section>
<section className="mt-6">
<h2 className="admin-section-title">{t("texts")}</h2>
<p className="text-xs theme-text-muted dark:theme-text-muted mb-3">
{t("keysCount", { count: textsCount })}
{textsTruncated
? ` (${t("showingFirst", { count: texts.length })})`
: ""}
.
</p>
<form action={updateEmulatorText} className="admin-card mb-6">
<h3 className="text-sm font-bold text-[var(--admin-text)] m-0 mb-3">
{t("addOverwriteText")}
</h3>
<div className="flex gap-2 flex-wrap">
<input name="key" placeholder={t("key")} maxLength={100} required />
<input
name="value"
placeholder={t("value")}
maxLength={4096}
className="flex-1 min-w-[200px]"
/>
<Button type="submit" variant="default">
{t("save")}
</Button>
</div>
</form>
<table>
<thead>
<tr>
<th className="w-[320px]">{t("colKey")}</th>
<th>{t("colValue")}</th>
</tr>
</thead>
<tbody>
{texts.map((txt) => (
<tr key={txt.key}>
<td>
<strong>{txt.key}</strong>
</td>
<td>
<form action={updateEmulatorText} className="flex gap-2">
<input type="hidden" name="key" value={txt.key} />
<input
name="value"
defaultValue={txt.value}
maxLength={4096}
className="flex-1"
/>
<Button type="submit" variant="outline">
{t("save")}
</Button>
</form>
</td>
</tr>
))}
</tbody>
</table>
{texts.length === 0 ? (
<div className="admin-empty">{t("noTexts")}</div>
) : null}
{textsTruncated ? (
<p className="muted">
{t("truncatedHint", { shown: texts.length, total: textsCount })}
</p>
) : null}
</section>
</main>
);
}