54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
|
|
import { getServerSession } from "next-auth/next"
|
||
|
|
import { redirect } from "next/navigation"
|
||
|
|
import Link from "next/link"
|
||
|
|
import { prisma } from "@/app/lib/prisma"
|
||
|
|
import NewsForm from "../../NewsForm"
|
||
|
|
|
||
|
|
export default async function EditNewsPage({
|
||
|
|
params,
|
||
|
|
}: {
|
||
|
|
params: Promise<{ id: string }>
|
||
|
|
}) {
|
||
|
|
const session = await getServerSession()
|
||
|
|
|
||
|
|
if (!session) {
|
||
|
|
redirect("/admin/login")
|
||
|
|
}
|
||
|
|
|
||
|
|
const { id } = await params
|
||
|
|
const news = await prisma.news.findUnique({
|
||
|
|
where: { id: parseInt(id) },
|
||
|
|
})
|
||
|
|
|
||
|
|
if (!news) {
|
||
|
|
redirect("/admin/news")
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="min-h-screen bg-gray-50">
|
||
|
|
<nav className="bg-white border-b border-gray-200">
|
||
|
|
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
|
||
|
|
<h1 className="text-xl font-bold text-gray-900">编辑新闻</h1>
|
||
|
|
<Link href="/admin/news" className="text-sm text-gray-600 hover:text-gray-900">
|
||
|
|
返回列表
|
||
|
|
</Link>
|
||
|
|
</div>
|
||
|
|
</nav>
|
||
|
|
|
||
|
|
<main className="max-w-3xl mx-auto px-6 py-8">
|
||
|
|
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
|
||
|
|
<NewsForm
|
||
|
|
news={{
|
||
|
|
id: news.id,
|
||
|
|
title: news.title,
|
||
|
|
content: news.content,
|
||
|
|
type: news.type,
|
||
|
|
published: news.published,
|
||
|
|
}}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
</main>
|
||
|
|
</div>
|
||
|
|
)
|
||
|
|
}
|