diff --git a/actions/accounts.ts b/actions/accounts.ts new file mode 100644 index 0000000..4c78027 --- /dev/null +++ b/actions/accounts.ts @@ -0,0 +1,26 @@ +"use server"; + +import prisma from "@/lib/prisma"; +import { Users } from "@prisma/client"; + +interface GetAccountsParameters { + take?: number; + skip?: number; +} + +export async function getAccounts(args?: GetAccountsParameters): Promise[]> { + return await prisma.users.findMany({ + take: args?.take, + skip: args?.skip, + orderBy: { + id: "asc", + }, + select: { + id: true, + firstName: true, + lastName: true, + isAdmin: true, + isTeacher: true, + } + }); +} \ No newline at end of file diff --git a/app/dashboard/Accounts.tsx b/app/dashboard/Accounts.tsx new file mode 100644 index 0000000..53750af --- /dev/null +++ b/app/dashboard/Accounts.tsx @@ -0,0 +1,14 @@ +import { getAccounts } from '@/actions/accounts'; +import prisma from '@/lib/prisma'; + +export async function Accounts() { + const users = await getAccounts({ take: 2 }); + + console.log(users); + + return ( +
+

Accounts

+
+ ); +} diff --git a/app/dashboard/ActiveCard.tsx b/app/dashboard/ActiveCard.tsx deleted file mode 100644 index 4152d49..0000000 --- a/app/dashboard/ActiveCard.tsx +++ /dev/null @@ -1,22 +0,0 @@ -'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/Simulation.tsx b/app/dashboard/Simulation.tsx new file mode 100644 index 0000000..f0e3eab --- /dev/null +++ b/app/dashboard/Simulation.tsx @@ -0,0 +1,7 @@ +export function Simulation() { + return ( +
+

Simulation

+
+ ); +} diff --git a/app/dashboard/Tabs.tsx b/app/dashboard/Tabs.tsx new file mode 100644 index 0000000..fcd3011 --- /dev/null +++ b/app/dashboard/Tabs.tsx @@ -0,0 +1,22 @@ +import { TabsContent, TabsList, TabsTrigger, Tabs as TabsShad } from '@/components/ui/tabs'; +import { Simulation } from './Simulation'; +import { Accounts } from './Accounts'; + +export function Tabs() { + return ( + + + Simulation + Comptes + {/* Exercices */} + Statistiques + + + + + + + + + ); +} diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 3ef202e..3025ddf 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -1,30 +1,21 @@ import prisma from '@/lib/prisma'; -import ActiveCard from './ActiveCard'; import { getAuthServerSession } from '@/lib/authenticate'; import { redirect } from 'next/navigation'; +import { Tabs } from './Tabs'; export default async function Dashboard() { - const authSession = await getAuthServerSession(); - console.log(authSession); - if (!authSession) return redirect('/'); + const session = await getAuthServerSession(); + console.log(session?.user); + if (!session || !(session.user.isAdmin || session.user.isTeacher)) return redirect('/'); const tests = await prisma.test.findMany({ select: { isActive: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } }); const activeTests = tests.filter((test) => test.isActive); return ( -
-

Dashboard

-
-

Test(s) Actif(s) :

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

Dashboard

+
); } diff --git a/components/ui/tabs.tsx b/components/ui/tabs.tsx new file mode 100644 index 0000000..26eb109 --- /dev/null +++ b/components/ui/tabs.tsx @@ -0,0 +1,55 @@ +"use client" + +import * as React from "react" +import * as TabsPrimitive from "@radix-ui/react-tabs" + +import { cn } from "@/lib/utils" + +const Tabs = TabsPrimitive.Root + +const TabsList = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +TabsList.displayName = TabsPrimitive.List.displayName + +const TabsTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +TabsTrigger.displayName = TabsPrimitive.Trigger.displayName + +const TabsContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +TabsContent.displayName = TabsPrimitive.Content.displayName + +export { Tabs, TabsList, TabsTrigger, TabsContent }