- 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
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import { Newspaper } from "lucide-react";
|
|
import Link from "next/link";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import { getTranslations } from "next-intl/server";
|
|
import { deleteArticle, updateArticle } from "@/actions/admin-articles";
|
|
import { ArticleForm } from "@/components/admin/article-form";
|
|
import { Button } from "@/components/ui/button";
|
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function EditArticle({
|
|
params,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ id: string }>;
|
|
searchParams: Promise<{ error?: string }>;
|
|
}) {
|
|
const { session, permissions } = await getAdminContext();
|
|
if (!canAccess(permissions, PERMS.NEWS_VIEW, session.user.rank)) {
|
|
redirect("/admin");
|
|
}
|
|
|
|
const { id } = await params;
|
|
const { error } = await searchParams;
|
|
const t = await getTranslations("pages.admin.articles");
|
|
const article = await prisma.websiteArticles
|
|
.findUnique({
|
|
where: { id: BigInt(id) },
|
|
select: {
|
|
id: true,
|
|
slug: true,
|
|
title: true,
|
|
shortStory: true,
|
|
fullStory: true,
|
|
image: true,
|
|
},
|
|
})
|
|
.catch(() => null);
|
|
if (!article) 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">
|
|
<Newspaper size={20} className="text-[var(--admin-accent)]" />
|
|
</div>
|
|
<div>
|
|
<h1 className="m-0 text-xl font-extrabold text-[var(--admin-text)]">
|
|
{t("form.title")}
|
|
</h1>
|
|
<p className="m-0 text-xs text-[var(--admin-text-muted)] mt-0.5">
|
|
<Link href="/admin/articles">← {t("title")}</Link>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
{error ? (
|
|
<p className="text-xs text-[var(--admin-error)] dark:text-[var(--admin-error)] mb-4">
|
|
Error: {error}
|
|
</p>
|
|
) : null}
|
|
<ArticleForm
|
|
action={async (fd) => {
|
|
"use server";
|
|
fd.set("id", String(article.id));
|
|
await updateArticle(fd);
|
|
}}
|
|
defaultValues={{
|
|
title: article.title,
|
|
slug: article.slug,
|
|
image: article.image,
|
|
shortStory: article.shortStory,
|
|
fullStory: article.fullStory,
|
|
}}
|
|
/>
|
|
<form action={deleteArticle} style={{ marginTop: "1rem" }}>
|
|
<input type="hidden" name="id" value={String(article.id)} />
|
|
<Button type="submit" variant="default">
|
|
{t("form.deleteArticle")}
|
|
</Button>
|
|
</form>
|
|
</main>
|
|
);
|
|
}
|