mirror of
https://github.com/Fayorg/calendrier-avant.git
synced 2026-05-28 01:28:37 +02:00
Compare commits
5 Commits
master
...
ef45d7eac7
| Author | SHA1 | Date | |
|---|---|---|---|
| ef45d7eac7 | |||
| 8b32c62754 | |||
| 2e2a44cb5d | |||
| 03f5321062 | |||
| 01e87a75d6 |
26
actions/accounts.ts
Normal file
26
actions/accounts.ts
Normal file
@@ -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,
|
||||
}
|
||||
});
|
||||
}
|
||||
14
app/dashboard/Accounts.tsx
Normal file
14
app/dashboard/Accounts.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
7
app/dashboard/Simulation.tsx
Normal file
7
app/dashboard/Simulation.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
export function Simulation() {
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-white">Simulation</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
app/dashboard/Tabs.tsx
Normal file
22
app/dashboard/Tabs.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
55
components/ui/tabs.tsx
Normal file
55
components/ui/tabs.tsx
Normal 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 }
|
||||
@@ -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
|
||||
@@ -32,6 +33,7 @@ export const authOptions: NextAuthOptions = {
|
||||
token.firstName = user.firstName;
|
||||
token.lastName = user.lastName;
|
||||
token.isTeacher = user.isTeacher;
|
||||
token.isAdmin = user.isAdmin;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
@@ -41,6 +43,7 @@ export const authOptions: NextAuthOptions = {
|
||||
session.user.firstName = token.firstName;
|
||||
session.user.lastName = token.lastName;
|
||||
session.user.isTeacher = token.isTeacher;
|
||||
session.user.isAdmin = token.isAdmin;
|
||||
}
|
||||
return session;
|
||||
},
|
||||
|
||||
@@ -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})));
|
||||
62
package-lock.json
generated
62
package-lock.json
generated
@@ -13,6 +13,7 @@
|
||||
"@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",
|
||||
"chart.js": "^4.4.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
@@ -1276,6 +1277,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 +1402,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",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"@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",
|
||||
"chart.js": "^4.4.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
|
||||
@@ -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[]
|
||||
|
||||
3
types/next-auth.d.ts
vendored
3
types/next-auth.d.ts
vendored
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user