import { notFound } from "next/navigation";
import { prisma } from "@/lib/db";
import { getConsoleContext } from "@/lib/console";
import { REQUIRED_APPROVALS } from "@/lib/posts/workflow";
import { approversForPages } from "@/lib/posts/approvers";
import { PostEditor } from "@/components/PostEditor";
import { PageTitle } from "@/components/ui";
export default async function PostPage(props: PageProps<"/posts/[id]">) {
const { id } = await props.params;
const ctx = await getConsoleContext();
const post = await prisma.post.findUnique({ where: { id } });
const page = post && ctx.pages.find((p) => p.id === post.pageId);
if (!post || !page) notFound();
const [approvalsCount, log, approvalRequest, approvers] = await Promise.all([
prisma.postApproval.count({ where: { postId: id } }),
prisma.auditLog.findMany({ where: { postId: id }, orderBy: { createdAt: "desc" }, take: 30 }),
prisma.approvalRequest.findUnique({ where: { postId: id }, select: { assigneeId: true, requesterId: true, status: true, assignee: { select: { name: true } } } }),
approversForPages([post.pageId]),
]);
return (
<>
({
id: l.id,
action: l.action,
actorLabel: l.actorLabel,
createdAt: l.createdAt.toISOString(),
note: (l.detail as { note?: string } | null)?.note ?? null,
}))}
approvalsCount={approvalsCount}
approvers={approvers}
approvalRequest={approvalRequest}
requiredApprovals={REQUIRED_APPROVALS}
currentUserId={ctx.user.id}
superadmin={ctx.user.globalRole === "SUPERADMIN"}
/>
>
);
}