feat: implement ClassList component to display classes; update UserList to show associated classes and handle empty states
This commit is contained in:
parent
52274f204c
commit
0cc0d18558
@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack -p 4000",
|
"dev": "next dev -p 4000",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"build:docker": "docker build -t toogether/webapp .",
|
"build:docker": "docker build -t toogether/webapp .",
|
||||||
"start": "next start -p 4000",
|
"start": "next start -p 4000",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { ClassList } from "@/app/components/Class";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
@ -5,5 +6,5 @@ export const metadata: Metadata = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
return <p>Hello world!</p>;
|
return <ClassList />;
|
||||||
}
|
}
|
||||||
|
71
src/app/components/Class/index.tsx
Normal file
71
src/app/components/Class/index.tsx
Normal file
@ -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<Class[]>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
classesService.getAll().then((response) => {
|
||||||
|
setClasses(response.data);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!classes) {
|
||||||
|
return (
|
||||||
|
<Card className="w-full space-y-5 p-4" radius="lg">
|
||||||
|
<Skeleton className="rounded-lg">
|
||||||
|
<div className="h-10 rounded-lg bg-default-300" />
|
||||||
|
</Skeleton>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Skeleton className="w-3/5 rounded-lg">
|
||||||
|
<div className="h-3 w-3/5 rounded-lg bg-default-200" />
|
||||||
|
</Skeleton>
|
||||||
|
<Skeleton className="w-4/5 rounded-lg">
|
||||||
|
<div className="h-3 w-4/5 rounded-lg bg-default-200" />
|
||||||
|
</Skeleton>
|
||||||
|
<Skeleton className="w-2/5 rounded-lg">
|
||||||
|
<div className="h-3 w-2/5 rounded-lg bg-default-300" />
|
||||||
|
</Skeleton>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classes.length === 0) {
|
||||||
|
return (
|
||||||
|
<Card className="w-full p-4" radius="lg">
|
||||||
|
<p className="text-center text-lg text-gray-500 dark:text-gray-400">
|
||||||
|
No classes found
|
||||||
|
</p>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table aria-label="List of users" className="w-full">
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>NAME</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{classes.map((Class) => (
|
||||||
|
<TableRow key={Class.id.toString()}>
|
||||||
|
<TableCell>{Class.name}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
);
|
||||||
|
};
|
@ -43,16 +43,36 @@ export const UserList = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (users.length === 0) {
|
||||||
|
return (
|
||||||
|
<Card className="w-full p-4" radius="lg">
|
||||||
|
<p className="text-center text-lg text-gray-500 dark:text-gray-400">
|
||||||
|
No users found
|
||||||
|
</p>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table aria-label="List of users" className="w-full">
|
<Table aria-label="List of users" className="w-full">
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableColumn>USERNAME</TableColumn>
|
<TableColumn>USERNAME</TableColumn>
|
||||||
|
<TableColumn>CLASS</TableColumn>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{users &&
|
{users.map((user) => (
|
||||||
users.map((user) => (
|
|
||||||
<TableRow key={user.id.toString()}>
|
<TableRow key={user.id.toString()}>
|
||||||
<TableCell>{user.username}</TableCell>
|
<TableCell>{user.username}</TableCell>
|
||||||
|
<TableCell className="flex flex-wrap gap-1">
|
||||||
|
{user.Class.map((c) => (
|
||||||
|
<span
|
||||||
|
className="px-2 rounded-md bg-foreground-100"
|
||||||
|
key={c.id.toString()}
|
||||||
|
>
|
||||||
|
{c.name}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
export interface User {
|
export interface User {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
|
||||||
|
Class: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
createdAt: string;
|
||||||
|
}[];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user