26 lines
1.4 KiB
TypeScript
26 lines
1.4 KiB
TypeScript
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 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
|
|
user={{ name: ctx.user.name, email: ctx.user.email, avatarUrl: ctx.user.avatarUrl, superadmin: ctx.user.globalRole === "SUPERADMIN" }}
|
|
pages={ctx.pages.map(({ id, name, pictureUrl, status }) => ({ id, name, pictureUrl, status }))}
|
|
selectedId={ctx.selected?.id ?? null}
|
|
counts={{ pendingApprovals }}
|
|
>
|
|
{children}
|
|
</Shell>
|
|
);
|
|
}
|