import { auth } from "@/auth"; import { db } from "@/lib/db"; import { redirect } from "next/navigation"; import { Sidebar } from "@/components/layout/sidebar"; import { Header } from "@/components/layout/header"; import { MobileHeader } from "@/components/layout/mobile-header"; import { MobileBottomNav } from "@/components/layout/mobile-bottom-nav"; import { DesktopRequired } from "@/components/layout/desktop-required"; // Roles that have a useful mobile experience const MOBILE_ROLES = ["MANAGER", "SUPERUSER", "ACCOUNTS"] as const; export default async function PortalLayout({ children, }: { children: React.ReactNode; }) { const session = await auth(); if (!session?.user) redirect("/login"); const hasMobile = (MOBILE_ROLES as readonly string[]).includes(session.user.role); const [notifications, unreadCount] = await Promise.all([ db.notification.findMany({ where: { userId: session.user.id }, orderBy: { sentAt: "desc" }, take: 20, select: { id: true, body: true, link: true, isRead: true, sentAt: true, poId: true }, }), db.notification.count({ where: { userId: session.user.id, isRead: false }, }), ]); // Dates must be serialised before being passed to Client Components const serialisedNotifications = notifications.map((n) => ({ ...n, sentAt: n.sentAt.toISOString(), })); return (