import { prisma } from "@/lib/prisma"; import { getServerSession } from "next-auth/next"; import { authOptions } from "@/lib/auth-config"; import { redirect } from "next/navigation"; import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import Link from "next/link"; export const dynamic = "force-dynamic"; export default async function StudentsPage() { const session = await getServerSession(authOptions); if (!session?.user) redirect("/login"); if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard"); const establishmentId = session.user.establishmentId; const students = await prisma.student.findMany({ where: establishmentId ? { class: { establishmentId } } : {}, include: { class: true, nodes: true }, orderBy: { createdAt: "desc" }, }); return (

Étudiants

Nom Classe Email Code activation Nœud {students.map((s) => { const node = s.nodes[0]; return ( {s.firstName} {s.lastName} {s.class.name} {s.email} {s.activationCode || "-"} {node ? ( {node.status} ) : ( Non lié )} ); })} {students.length === 0 && ( Aucun étudiant )}
); }