Files
PAGIVA/src/app/(console)/posts/[id]/page.tsx
T
2026-11-24 11:13:20 +07:00

63 lines
2.5 KiB
TypeScript

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 (
<>
<PageTitle title={post.title} subtitle={page.name} />
<PostEditor
// Remount on every server update so local form state matches the saved post.
key={post.updatedAt.toISOString()}
pages={[{ id: page.id, name: page.name, pictureUrl: page.pictureUrl, igUsername: page.igUsername, role: page.role }]}
post={{
id: post.id,
pageId: post.pageId,
title: post.title,
caption: post.caption,
imageBlobUrl: post.imageBlobUrl,
targets: post.targets,
status: post.status,
scheduledPublishAt: post.scheduledPublishAt?.toISOString() ?? null,
fbPermalink: post.fbPermalink,
igPermalink: post.igPermalink,
lastError: post.lastError,
lastEditedById: post.lastEditedById,
createdById: post.createdById,
aiAssisted: post.aiAssisted,
}}
log={log.map((l) => ({
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"}
/>
</>
);
}