- Replace 'card' class with 'admin-card' (gradient cards, dark mode support) - Replace 'muted' class with consistent Tailwind muted states - Standardize page headers with gradient backgrounds and Lucide icons - Convert all inline styles to Tailwind classes - Add admin-page CSS helpers (admin-card, admin-filter-bar, admin-section-title) - Apply pattern to all 42 admin pages (was only 6 before) - Zero TypeScript errors, production builds successfully Co-authored-by: openhands <[email protected]>
61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import Link from "next/link";
|
|
import { Newspaper } from "lucide-react";
|
|
import { notFound } from "next/navigation";
|
|
import { deleteArticle, updateArticle } from "@/actions/admin-articles";
|
|
import { ArticleForm } from "@/components/admin/article-form";
|
|
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 { id } = await params;
|
|
const { error } = await searchParams;
|
|
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(--color-primary)]/20 to-[var(--color-primary)]/5 grid place-items-center">
|
|
<Newspaper size={20} className="text-[var(--color-primary)]" />
|
|
</div>
|
|
<div>
|
|
<h1 className="m-0 text-xl font-extrabold text-[var(--color-text)]">Edit article</h1>
|
|
<p className="m-0 text-xs text-[var(--color-text-muted)] mt-0.5"><Link href="/admin/articles">← Articles</Link></p>
|
|
</div>
|
|
</div>
|
|
{error ? (
|
|
<p className="text-xs text-red-600 dark:text-red-400 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,
|
|
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" className="btn btn-primary">Delete article</button>
|
|
</form>
|
|
</main>
|
|
);
|
|
}
|