add: dashboard tabs
This commit is contained in:
parent
8b32c62754
commit
ef45d7eac7
|
@ -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<Pick<Users, "id" | "firstName" | "lastName" | "isAdmin" | "isTeacher">[]> {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -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 (
|
||||||
|
<div>
|
||||||
|
<h1 className="text-white">Accounts</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -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 (
|
|
||||||
<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,7 @@
|
||||||
|
export function Simulation() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1 className="text-white">Simulation</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -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 (
|
||||||
|
<TabsShad defaultValue="simulation" className="w-[400px]">
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="simulation">Simulation</TabsTrigger>
|
||||||
|
<TabsTrigger value="accounts">Comptes</TabsTrigger>
|
||||||
|
{/* <TabsTrigger value="exercices">Exercices</TabsTrigger> */}
|
||||||
|
<TabsTrigger value="statistics">Statistiques</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<TabsContent value="simulation">
|
||||||
|
<Simulation />
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="accounts">
|
||||||
|
<Accounts />
|
||||||
|
</TabsContent>
|
||||||
|
</TabsShad>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,30 +1,21 @@
|
||||||
import prisma from '@/lib/prisma';
|
import prisma from '@/lib/prisma';
|
||||||
import ActiveCard from './ActiveCard';
|
|
||||||
import { getAuthServerSession } from '@/lib/authenticate';
|
import { getAuthServerSession } from '@/lib/authenticate';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
import { Tabs } from './Tabs';
|
||||||
|
|
||||||
export default async function Dashboard() {
|
export default async function Dashboard() {
|
||||||
const authSession = await getAuthServerSession();
|
const session = await getAuthServerSession();
|
||||||
console.log(authSession);
|
console.log(session?.user);
|
||||||
if (!authSession) return redirect('/');
|
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 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);
|
const activeTests = tests.filter((test) => test.isActive);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="container flex flex-col gap-4 my-4">
|
||||||
<h1>Dashboard</h1>
|
<h1 className="text-4xl text-white font-bold">Dashboard</h1>
|
||||||
<div className="border-2 border-white rounded-2xl bg-red-500 p-2">
|
<Tabs />
|
||||||
<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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<typeof TabsPrimitive.List>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.List
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
TabsList.displayName = TabsPrimitive.List.displayName
|
||||||
|
|
||||||
|
const TabsTrigger = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.Trigger
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
|
||||||
|
|
||||||
|
const TabsContent = React.forwardRef<
|
||||||
|
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<TabsPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
TabsContent.displayName = TabsPrimitive.Content.displayName
|
||||||
|
|
||||||
|
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
Loading…
Reference in New Issue