1
0
mirror of https://github.com/Fayorg/calendrier-avant.git synced 2026-05-27 17:18:38 +02:00

Compare commits

...

7 Commits

Author SHA1 Message Date
4e7dede837 add: idk 2024-08-15 21:08:38 -04:00
d21aaa1757 add: shadcn tableData component 2023-12-20 21:12:43 +01:00
ef45d7eac7 add: dashboard tabs 2023-12-20 19:36:52 +01:00
8b32c62754 add: new property on session & token 2023-12-20 19:36:35 +01:00
2e2a44cb5d add: shadcn Tab component 2023-12-20 19:35:53 +01:00
03f5321062 fix: removed unused featcher 2023-12-20 15:19:00 +01:00
01e87a75d6 add: canVote field in db 2023-12-20 15:16:23 +01:00
15 changed files with 402 additions and 60 deletions

28
actions/accounts.ts Normal file
View File

@@ -0,0 +1,28 @@
"use server";
import prisma from "@/lib/prisma";
import { Users } from "@prisma/client";
interface GetAccountsParameters {
take?: number;
skip?: number;
}
export type Account = Pick<Users, "id" | "firstName" | "lastName" | "isAdmin" | "isTeacher">;
export async function getAccounts(args?: GetAccountsParameters): Promise<Account[]> {
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,
}
});
}

View File

@@ -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>
);
}

View File

@@ -0,0 +1,30 @@
'use client';
import { Account } from '@/actions/accounts';
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"
export const columns: ColumnDef<Account>[] = [
{
accessorKey: 'lastName',
header: 'Last Name',
},
{
accessorKey: 'firstName',
header: 'First Name',
},
];
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[]
data: TData[]
}
export function DataTable<TData, TValue>({
columns,
data,
}: DataTableProps<TData, TValue>) {
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
})

View File

@@ -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>
);
}

View File

@@ -0,0 +1,7 @@
export function Simulation() {
return (
<div>
<h1 className="text-white">Simulation</h1>
</div>
);
}

22
app/dashboard/Tabs.tsx Normal file
View File

@@ -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>
);
}

View File

@@ -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 (
<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 className="container flex flex-col gap-4 my-4">
<h1 className="text-4xl text-white font-bold">Dashboard</h1>
<Tabs />
</div>
);
}

117
components/ui/table.tsx Normal file
View File

@@ -0,0 +1,117 @@
import * as React from "react"
import { cn } from "@/lib/utils"
const Table = React.forwardRef<
HTMLTableElement,
React.HTMLAttributes<HTMLTableElement>
>(({ className, ...props }, ref) => (
<div className="relative w-full overflow-auto">
<table
ref={ref}
className={cn("w-full caption-bottom text-sm", className)}
{...props}
/>
</div>
))
Table.displayName = "Table"
const TableHeader = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
))
TableHeader.displayName = "TableHeader"
const TableBody = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<tbody
ref={ref}
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
))
TableBody.displayName = "TableBody"
const TableFooter = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<tfoot
ref={ref}
className={cn(
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/>
))
TableFooter.displayName = "TableFooter"
const TableRow = React.forwardRef<
HTMLTableRowElement,
React.HTMLAttributes<HTMLTableRowElement>
>(({ className, ...props }, ref) => (
<tr
ref={ref}
className={cn(
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
className
)}
{...props}
/>
))
TableRow.displayName = "TableRow"
const TableHead = React.forwardRef<
HTMLTableCellElement,
React.ThHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
<th
ref={ref}
className={cn(
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
))
TableHead.displayName = "TableHead"
const TableCell = React.forwardRef<
HTMLTableCellElement,
React.TdHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
<td
ref={ref}
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
{...props}
/>
))
TableCell.displayName = "TableCell"
const TableCaption = React.forwardRef<
HTMLTableCaptionElement,
React.HTMLAttributes<HTMLTableCaptionElement>
>(({ className, ...props }, ref) => (
<caption
ref={ref}
className={cn("mt-4 text-sm text-muted-foreground", className)}
{...props}
/>
))
TableCaption.displayName = "TableCaption"
export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
}

55
components/ui/tabs.tsx Normal file
View File

@@ -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 }

View File

@@ -9,7 +9,8 @@ export async function authenticate(key: string) {
id: true,
firstName: true,
lastName: true,
isTeacher: true
isTeacher: true,
isAdmin: true
},
where: {
key: key
@@ -26,24 +27,26 @@ export const authOptions: NextAuthOptions = {
strategy: "jwt",
},
callbacks: {
async jwt({ token, user }) {
if (user) {
token.userId = parseInt(user.id as string);
token.firstName = user.firstName;
token.lastName = user.lastName;
token.isTeacher = user.isTeacher;
}
return token;
},
async session({ session, token, user }) {
if(token) {
session.user.id = token.userId;
session.user.firstName = token.firstName;
session.user.lastName = token.lastName;
session.user.isTeacher = token.isTeacher;
}
return session;
},
async jwt({ token, user }) {
if (user) {
token.userId = parseInt(user.id as string);
token.firstName = user.firstName;
token.lastName = user.lastName;
token.isTeacher = user.isTeacher;
token.isAdmin = user.isAdmin;
}
return token;
},
async session({ session, token, user }) {
if(token) {
session.user.id = token.userId;
session.user.firstName = token.firstName;
session.user.lastName = token.lastName;
session.user.isTeacher = token.isTeacher;
session.user.isAdmin = token.isAdmin;
}
return session;
},
},
pages: {
signIn: '/',

View File

@@ -1,3 +0,0 @@
import { stat } from "fs";
export const fetcher = (input: URL | RequestInfo, init?: RequestInit | undefined) => fetch(input, init).then(res => res.json().then(data => ({...data, status: res.status})));

94
package-lock.json generated
View File

@@ -13,7 +13,9 @@
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-table": "^8.11.2",
"chart.js": "^4.4.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
@@ -1276,6 +1278,37 @@
}
}
},
"node_modules/@radix-ui/react-roving-focus": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@radix-ui/react-roving-focus/-/react-roving-focus-1.0.4.tgz",
"integrity": "sha512-2mUg5Mgcu001VkGy+FfzZyzbmuUWzgWkj3rvv4yu+mLw03+mTzbxZHvfcGyFp2b8EkQeMkpRQ5FiA2Vr2O6TeQ==",
"dependencies": {
"@babel/runtime": "^7.13.10",
"@radix-ui/primitive": "1.0.1",
"@radix-ui/react-collection": "1.0.3",
"@radix-ui/react-compose-refs": "1.0.1",
"@radix-ui/react-context": "1.0.1",
"@radix-ui/react-direction": "1.0.1",
"@radix-ui/react-id": "1.0.1",
"@radix-ui/react-primitive": "1.0.3",
"@radix-ui/react-use-callback-ref": "1.0.1",
"@radix-ui/react-use-controllable-state": "1.0.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-select": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-2.0.0.tgz",
@@ -1370,6 +1403,36 @@
}
}
},
"node_modules/@radix-ui/react-tabs": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.0.4.tgz",
"integrity": "sha512-egZfYY/+wRNCflXNHx+dePvnz9FbmssDTJBtgRfDY7e8SE5oIo3Py2eCB1ckAbh1Q7cQ/6yJZThJ++sgbxibog==",
"dependencies": {
"@babel/runtime": "^7.13.10",
"@radix-ui/primitive": "1.0.1",
"@radix-ui/react-context": "1.0.1",
"@radix-ui/react-direction": "1.0.1",
"@radix-ui/react-id": "1.0.1",
"@radix-ui/react-presence": "1.0.1",
"@radix-ui/react-primitive": "1.0.3",
"@radix-ui/react-roving-focus": "1.0.4",
"@radix-ui/react-use-controllable-state": "1.0.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-toast": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/@radix-ui/react-toast/-/react-toast-1.1.5.tgz",
@@ -1577,6 +1640,37 @@
"tslib": "^2.4.0"
}
},
"node_modules/@tanstack/react-table": {
"version": "8.11.2",
"resolved": "https://registry.npmjs.org/@tanstack/react-table/-/react-table-8.11.2.tgz",
"integrity": "sha512-ztLg2OpM3HZIWzkQYjQER1inZuhbt79fBwZxc9bPXzsvqY+7RYI3dCZLw3CynYd9s4YltdrTbmSyh4xQSHexDQ==",
"dependencies": {
"@tanstack/table-core": "8.11.2"
},
"engines": {
"node": ">=12"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/tannerlinsley"
},
"peerDependencies": {
"react": ">=16",
"react-dom": ">=16"
}
},
"node_modules/@tanstack/table-core": {
"version": "8.11.2",
"resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-8.11.2.tgz",
"integrity": "sha512-rR0VEQOtr0ARLvaNLaSQnt2BVwOp0OavOUA0LcZ3N45tLYXc4sXruNv8kJ7R7+5W1CrzGha217tzjBG83CpoMQ==",
"engines": {
"node": ">=12"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/tannerlinsley"
}
},
"node_modules/@types/cookie": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz",

View File

@@ -14,7 +14,9 @@
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-table": "^8.11.2",
"chart.js": "^4.4.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",

View File

@@ -24,6 +24,7 @@ model Test {
id Int @id @default(autoincrement())
testOfId Int @unique
testOn DateTime @db.Date
canVote Boolean @default(false)
createdAt DateTime @default(now())
testOf Users @relation(fields: [testOfId], references: [id])
grades Grade[]

View File

@@ -8,6 +8,7 @@ declare module "next-auth" {
firstName: string;
lastName: string
isTeacher: boolean;
isAdmin: boolean;
} & DefaultSession["user"];
}
interface User {
@@ -15,6 +16,7 @@ declare module "next-auth" {
firstName: string;
lastName: string
isTeacher: boolean;
isAdmin: boolean;
}
}
@@ -24,5 +26,6 @@ declare module "next-auth/jwt" {
firstName: string;
lastName: string
isTeacher: boolean;
isAdmin: boolean;
}
}