Initial commit: EduBox V2 platform
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function ClassesPage() {
|
||||
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 classes = await prisma.class.findMany({
|
||||
where: establishmentId ? { establishmentId } : {},
|
||||
include: { _count: { select: { students: true } } },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Classes</h1>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nom</TableHead>
|
||||
<TableHead>Niveau</TableHead>
|
||||
<TableHead>Étudiants</TableHead>
|
||||
<TableHead>Créée le</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{classes.map((cls) => (
|
||||
<TableRow key={cls.id}>
|
||||
<TableCell className="font-medium">{cls.name}</TableCell>
|
||||
<TableCell>{cls.level}</TableCell>
|
||||
<TableCell>{cls._count.students}</TableCell>
|
||||
<TableCell>{new Date(cls.createdAt).toLocaleDateString("fr-FR")}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{classes.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4} className="text-center text-muted-foreground">Aucune classe</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user