From 0cc0d1855836c3db0aa17093cbb3782eff140bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Wed, 8 Jan 2025 00:20:56 +0100 Subject: [PATCH] feat: implement ClassList component to display classes; update UserList to show associated classes and handle empty states --- package.json | 2 +- src/app/admin/classes/page.tsx | 3 +- src/app/components/Class/index.tsx | 71 ++++++++++++++++++++++++++++++ src/app/components/Users/index.tsx | 32 +++++++++++--- src/app/interface/user.ts | 6 +++ 5 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 src/app/components/Class/index.tsx diff --git a/package.json b/package.json index b4fb6a5..208878f 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev --turbopack -p 4000", + "dev": "next dev -p 4000", "build": "next build", "build:docker": "docker build -t toogether/webapp .", "start": "next start -p 4000", diff --git a/src/app/admin/classes/page.tsx b/src/app/admin/classes/page.tsx index 938e852..fc96c89 100644 --- a/src/app/admin/classes/page.tsx +++ b/src/app/admin/classes/page.tsx @@ -1,3 +1,4 @@ +import { ClassList } from "@/app/components/Class"; import { Metadata } from "next"; export const metadata: Metadata = { @@ -5,5 +6,5 @@ export const metadata: Metadata = { }; export default async function Page() { - return

Hello world!

; + return ; } diff --git a/src/app/components/Class/index.tsx b/src/app/components/Class/index.tsx new file mode 100644 index 0000000..b3c6a67 --- /dev/null +++ b/src/app/components/Class/index.tsx @@ -0,0 +1,71 @@ +"use client"; +import { Class } from "@/app/interface/class"; +import { classesService } from "@/app/services/classes.service"; +import { + Card, + Skeleton, + Table, + TableBody, + TableCell, + TableColumn, + TableHeader, + TableRow, +} from "@nextui-org/react"; +import { useEffect, useState } from "react"; + +export const ClassList = () => { + const [classes, setClasses] = useState(); + + useEffect(() => { + classesService.getAll().then((response) => { + setClasses(response.data); + }); + }, []); + + if (!classes) { + return ( + + +
+ + +
+ +
+ + +
+ + +
+ +
+ + ); + } + + if (classes.length === 0) { + return ( + +

+ No classes found +

+
+ ); + } + + return ( + + + NAME + + + {classes.map((Class) => ( + + {Class.name} + + ))} + +
+ ); +}; diff --git a/src/app/components/Users/index.tsx b/src/app/components/Users/index.tsx index 9afc5ca..ef6aeea 100644 --- a/src/app/components/Users/index.tsx +++ b/src/app/components/Users/index.tsx @@ -43,18 +43,38 @@ export const UserList = () => { ); } + if (users.length === 0) { + return ( + +

+ No users found +

+
+ ); + } + return ( USERNAME + CLASS - {users && - users.map((user) => ( - - {user.username} - - ))} + {users.map((user) => ( + + {user.username} + + {user.Class.map((c) => ( + + {c.name} + + ))} + + + ))}
); diff --git a/src/app/interface/user.ts b/src/app/interface/user.ts index a102982..c3c1631 100644 --- a/src/app/interface/user.ts +++ b/src/app/interface/user.ts @@ -1,4 +1,10 @@ export interface User { id: string; username: string; + + Class: { + id: string; + name: string; + createdAt: string; + }[]; }