Add self-service teams and assigned post approvals
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user