feat: refactor user and room interfaces, update imports, and enhance user list component
This commit is contained in:
parent
b1f59249c0
commit
5bfc969f6a
@ -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 { UserList } from "@/app/components/Users";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
@ -5,5 +6,9 @@ export const metadata: Metadata = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
return <p>Users</p>;
|
return (
|
||||||
|
<div className="p-4">
|
||||||
|
<UserList />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
Divider,
|
Divider,
|
||||||
TimeInput,
|
TimeInput,
|
||||||
} from "@nextui-org/react";
|
} from "@nextui-org/react";
|
||||||
import { Room } from "../../types/room";
|
import { Room } from "../../interface/room";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { RoomCard } from "./Card";
|
import { RoomCard } from "./Card";
|
||||||
import { Room } from "../../types/room";
|
import { Room } from "../../interface/room";
|
||||||
import { SkeletonRoomCard } from "./SkeletonRoomCard";
|
import { SkeletonRoomCard } from "./SkeletonRoomCard";
|
||||||
|
|
||||||
export const RoomList = ({ rooms }: { rooms: Room[] | null }) => {
|
export const RoomList = ({ rooms }: { rooms: Room[] | null }) => {
|
||||||
|
61
src/app/components/Users/index.tsx
Normal file
61
src/app/components/Users/index.tsx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
"use client";
|
||||||
|
import { User } from "@/app/interface/user";
|
||||||
|
import { usersService } from "@/app/services/users.service";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
Skeleton,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableColumn,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
export const UserList = () => {
|
||||||
|
const [users, setUsers] = useState<User[]>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
usersService.getAll().then((response) => {
|
||||||
|
setUsers(response.data);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!users) {
|
||||||
|
return (
|
||||||
|
<Card className="w-[300px] 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table aria-label="List of users" className="w-[300px]">
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>USERNAME</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{users &&
|
||||||
|
users.map((user) => (
|
||||||
|
<TableRow key={user.id.toString()}>
|
||||||
|
<TableCell>{user.username}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
);
|
||||||
|
};
|
@ -5,6 +5,12 @@ export const API_URLS = {
|
|||||||
all: `${NEXT_PUBLIC_API_URL}/@me/class`,
|
all: `${NEXT_PUBLIC_API_URL}/@me/class`,
|
||||||
},
|
},
|
||||||
room: {
|
room: {
|
||||||
all: (classId: string) => `${NEXT_PUBLIC_API_URL}/@me/class/${classId}/rooms`,
|
all: (classId: string) =>
|
||||||
}
|
`${NEXT_PUBLIC_API_URL}/@me/class/${classId}/rooms`,
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
user: {
|
||||||
|
all: `${NEXT_PUBLIC_API_URL}/user`,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
interface Class {
|
export interface Class {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
4
src/app/interface/user.ts
Normal file
4
src/app/interface/user.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface User {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { API_URLS } from "../constants/apiUrl.constant";
|
import { API_URLS } from "../constants/apiUrl.constant";
|
||||||
import { axiosInstance } from "../lib/axios";
|
import { axiosInstance } from "../lib/axios";
|
||||||
import { Room } from "../types/room";
|
import { Room } from "../interface/room";
|
||||||
|
|
||||||
const getAll = (classId: string) => axiosInstance.get<Room[]>(API_URLS.room.all(classId));
|
const getAll = (classId: string) => axiosInstance.get<Room[]>(API_URLS.room.all(classId));
|
||||||
|
|
||||||
|
7
src/app/services/users.service.ts
Normal file
7
src/app/services/users.service.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { API_URLS } from "../constants/apiUrl.constant";
|
||||||
|
import { User } from "../interface/user";
|
||||||
|
import { axiosInstance } from "../lib/axios";
|
||||||
|
|
||||||
|
const getAll = () => axiosInstance.get<User[]>(API_URLS.admin.user.all);
|
||||||
|
|
||||||
|
export const usersService = { getAll };
|
@ -1,6 +1,6 @@
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { Room } from "../types/room";
|
import { Room } from "../interface/room";
|
||||||
import { useUserStore } from "./userStore";
|
import { useUserStore } from "./userStore";
|
||||||
import { roomsService } from "../services/rooms.service";
|
import { roomsService } from "../services/rooms.service";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user