- 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
143 lines
3.6 KiB
TypeScript
143 lines
3.6 KiB
TypeScript
import { HelpCircle } from "lucide-react";
|
|
import Link from "next/link";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import { deleteHelpQuestion, updateHelpQuestion } from "@/actions/admin-help";
|
|
import { Button } from "@/components/ui/button";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function EditHelpQuestion({
|
|
params,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ id: string }>;
|
|
searchParams: Promise<{ error?: string }>;
|
|
}) {
|
|
const { session, permissions } = await getAdminContext();
|
|
if (!canAccess(permissions, PERMS.PAGES_VIEW, session.user.rank)) {
|
|
redirect("/admin");
|
|
}
|
|
|
|
const { id } = await params;
|
|
const { error } = await searchParams;
|
|
let entry: Awaited<
|
|
ReturnType<typeof prisma.websiteHelpCenterCategories.findUnique>
|
|
> = null;
|
|
try {
|
|
entry = await prisma.websiteHelpCenterCategories.findUnique({
|
|
where: { id: BigInt(id) },
|
|
});
|
|
} catch {
|
|
notFound();
|
|
}
|
|
if (!entry) notFound();
|
|
|
|
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">
|
|
<HelpCircle size={20} className="text-[var(--admin-accent)]" />
|
|
</div>
|
|
<div className="flex-1">
|
|
<h1 className="m-0 text-xl font-extrabold text-[var(--admin-text)]">
|
|
Edit help-center entry
|
|
</h1>
|
|
<p className="m-0 text-xs text-[var(--admin-text-muted)] mt-0.5">
|
|
<Link href="/admin/help-questions">← Help Center</Link>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
{error ? (
|
|
<p
|
|
className="text-xs theme-text-muted dark:theme-text-muted mb-4"
|
|
style={{ color: "#dc2626" }}
|
|
>
|
|
Error: {error}
|
|
</p>
|
|
) : null}
|
|
<form
|
|
action={updateHelpQuestion}
|
|
className="admin-card"
|
|
style={{ display: "grid", gap: "0.6rem" }}
|
|
>
|
|
<input type="hidden" name="id" value={String(entry.id)} />
|
|
<input
|
|
name="name"
|
|
defaultValue={entry.name}
|
|
placeholder="Name / title"
|
|
required
|
|
maxLength={255}
|
|
/>
|
|
<textarea
|
|
name="content"
|
|
defaultValue={entry.content}
|
|
placeholder="Content"
|
|
rows={6}
|
|
required
|
|
/>
|
|
<input
|
|
name="position"
|
|
type="number"
|
|
min={1}
|
|
defaultValue={entry.position}
|
|
placeholder="Position"
|
|
/>
|
|
<input
|
|
name="imageUrl"
|
|
defaultValue={entry.imageUrl ?? ""}
|
|
placeholder="Image URL (optional)"
|
|
maxLength={255}
|
|
/>
|
|
<input
|
|
name="buttonText"
|
|
defaultValue={entry.buttonText ?? ""}
|
|
placeholder="Button text (optional)"
|
|
maxLength={255}
|
|
/>
|
|
<input
|
|
name="buttonUrl"
|
|
defaultValue={entry.buttonUrl ?? ""}
|
|
placeholder="Button URL (optional)"
|
|
maxLength={255}
|
|
/>
|
|
<label className="flex gap-1.5 items-center">
|
|
Button color
|
|
<input
|
|
name="buttonColor"
|
|
type="color"
|
|
defaultValue={entry.buttonColor}
|
|
/>
|
|
</label>
|
|
<label className="flex gap-1.5 items-center">
|
|
Button border color
|
|
<input
|
|
name="buttonBorderColor"
|
|
type="color"
|
|
defaultValue={entry.buttonBorderColor}
|
|
/>
|
|
</label>
|
|
<label className="flex gap-1.5 items-center">
|
|
<input
|
|
name="smallBox"
|
|
type="checkbox"
|
|
value="1"
|
|
defaultChecked={entry.smallBox}
|
|
/>
|
|
Small box
|
|
</label>
|
|
<Button type="submit" variant="default">
|
|
Save
|
|
</Button>
|
|
</form>
|
|
<form action={deleteHelpQuestion} style={{ marginTop: "1rem" }}>
|
|
<input type="hidden" name="id" value={String(entry.id)} />
|
|
<Button type="submit" variant="destructive">
|
|
Delete entry
|
|
</Button>
|
|
</form>
|
|
</main>
|
|
);
|
|
}
|