add: dashboard with server actions
This commit is contained in:
parent
5b8038126b
commit
564edb70f8
|
@ -0,0 +1,12 @@
|
||||||
|
"use server";
|
||||||
|
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export async function setTestActive(id: number, active: boolean) {
|
||||||
|
const users = await prisma.users.findFirst();
|
||||||
|
|
||||||
|
console.log(users);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { setTestActive } from '@/actions/mangeTest';
|
||||||
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||||
|
|
||||||
|
export default function ActiveCard() {
|
||||||
|
return (
|
||||||
|
<AlertDialog>
|
||||||
|
<AlertDialogTrigger>Open</AlertDialogTrigger>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Etes-vous sur de vouloir terminer ce test?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>Les votations ne seront plus ouverte pour ce test. Vous pouvez cependant le réactiver dans le dashboard.</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||||
|
<AlertDialogAction onClick={() => setTestActive(1, true)}>Continue</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import prisma from '@/lib/prisma';
|
||||||
|
import ActiveCard from './ActiveCard';
|
||||||
|
|
||||||
|
export default async function Dashboard() {
|
||||||
|
const tests = await prisma.test.findMany({ select: { isActive: true, isPassed: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } });
|
||||||
|
|
||||||
|
const activeTests = tests.filter((test) => test.isActive);
|
||||||
|
const passedTests = tests.filter((test) => test.isPassed);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Dashboard</h1>
|
||||||
|
<div className="border-2 border-white rounded-2xl bg-red-500 p-2">
|
||||||
|
<h2>Test(s) Actif(s) :</h2>
|
||||||
|
<ul>
|
||||||
|
{activeTests.map((test) => (
|
||||||
|
<li key={test.id}>
|
||||||
|
{test.testOf.firstName + ' ' + test.testOf.lastName} <ActiveCard />
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue