feat: add CRUD forms with Server Actions for establishments, users, classes, students

This commit is contained in:
root
2026-06-06 20:08:17 +00:00
parent 0a73a70820
commit a1883080d3
26 changed files with 1206 additions and 16 deletions
@@ -0,0 +1,22 @@
"use server";
import { prisma } from "@/lib/prisma";
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/lib/auth-config";
import { redirect } from "next/navigation";
export async function deleteClass(formData: FormData) {
const session = await getServerSession(authOptions);
if (!session?.user) redirect("/login");
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
const id = formData.get("id") as string;
if (!id) return;
const establishmentId = session.user.establishmentId;
await prisma.class.deleteMany({
where: { id, ...(establishmentId ? { establishmentId } : {}) },
});
redirect("/dashboard/classes");
}