import { getServerSession } from "next-auth"; import { authOptions } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; import { redirect } from "next/navigation"; import YogaDashboard from "./dashboard"; export default async function YogaPage() { const session = await getServerSession(authOptions); if (!session?.user) redirect("/login"); const user = await prisma.user.findUnique({ where: { id: session.user.id }, include: { yoga: { include: { attendances: { orderBy: { date: "desc" } }, }, }, }, }); if (!user) redirect("/login"); const messages = await prisma.message.findMany({ orderBy: { createdAt: "desc" }, where: { OR: [{ category: null }, { category: "general" }, { category: "yoga" }], }, include: { readBy: { where: { userId: user.id } }, }, }); const unreadCount = messages.filter((m) => m.readBy.length === 0).length; return ( ({ ...m, isRead: m.readBy.length > 0 }))} unreadCount={unreadCount} /> ); }