From 564edb70f8339b72746f1cd3e0ca535879e92e7c Mon Sep 17 00:00:00 2001 From: Fayorg Date: Fri, 15 Dec 2023 01:32:27 +0100 Subject: [PATCH] add: dashboard with server actions --- actions/mangeTest.ts | 12 ++++++++++++ app/dashboard/ActiveCard.tsx | 22 ++++++++++++++++++++++ app/dashboard/page.tsx | 25 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 actions/mangeTest.ts create mode 100644 app/dashboard/ActiveCard.tsx create mode 100644 app/dashboard/page.tsx diff --git a/actions/mangeTest.ts b/actions/mangeTest.ts new file mode 100644 index 0000000..74822da --- /dev/null +++ b/actions/mangeTest.ts @@ -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; + +} \ No newline at end of file diff --git a/app/dashboard/ActiveCard.tsx b/app/dashboard/ActiveCard.tsx new file mode 100644 index 0000000..4152d49 --- /dev/null +++ b/app/dashboard/ActiveCard.tsx @@ -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 ( + + Open + + + Etes-vous sur de vouloir terminer ce test? + Les votations ne seront plus ouverte pour ce test. Vous pouvez cependant le réactiver dans le dashboard. + + + Cancel + setTestActive(1, true)}>Continue + + + + ); +} diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx new file mode 100644 index 0000000..7cf6c54 --- /dev/null +++ b/app/dashboard/page.tsx @@ -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 ( +
+

Dashboard

+
+

Test(s) Actif(s) :

+
    + {activeTests.map((test) => ( +
  • + {test.testOf.firstName + ' ' + test.testOf.lastName} +
  • + ))} +
+
+
+ ); +}