Add self-service teams and assigned post approvals

This commit is contained in:
Loma Bot Ops
2026-11-24 11:13:20 +07:00
parent b14a9286cd
commit 55235718c3
31 changed files with 958 additions and 28 deletions
+6 -2
View File
@@ -1,12 +1,16 @@
import { prisma } from "@/lib/db";
import { getConsoleContext, scopedPageIds } from "@/lib/console";
import { Shell } from "@/components/Shell";
import { roleAtLeast } from "@/lib/auth/roles";
export default async function ConsoleLayout({ children }: { children: React.ReactNode }) {
const ctx = await getConsoleContext();
const pendingApprovals = await prisma.post.count({
where: { pageId: { in: scopedPageIds(ctx) }, status: "PENDING_APPROVAL" },
const assignedCount = await prisma.approvalRequest.count({
where: { assigneeId: ctx.user.id, status: "PENDING", post: { pageId: { in: scopedPageIds(ctx) }, status: "PENDING_APPROVAL" } },
});
const legacyPages = ctx.pages.filter((p) => roleAtLeast(p.role, "APPROVER") && (!ctx.selected || p.id === ctx.selected.id)).map((p) => p.id);
const legacy = await prisma.post.findMany({ where: { pageId: { in: legacyPages }, status: "PENDING_APPROVAL", approvalRequest: null }, select: { createdById: true, lastEditedById: true } });
const pendingApprovals = assignedCount + legacy.filter((p) => ctx.user.globalRole === "SUPERADMIN" || (p.createdById !== ctx.user.id && p.lastEditedById !== ctx.user.id)).length;
return (
<Shell