source: frontend/src/components/userProfile/AllUsersHelper.tsx@ 0d9725c

main
Last change on this file since 0d9725c was 0d9725c, checked in by Dimitar Arsov <dimitararsov04@…>, 6 months ago

initial user profile pages

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import { useEffect, useState } from "react";
2import { useNavigate } from "react-router-dom";
3
4interface User {
5 id: number;
6 username: string;
7 fullName: string;
8}
9
10const AllUsers = () => {
11 const [users, setUsers] = useState<User[]>([]);
12 const navigate = useNavigate();
13
14 useEffect(() => {
15 const fetchUsers = async () => {
16 const response = await fetch("http://localhost:8080/users/all");
17 const data = await response.json();
18 setUsers(data);
19 };
20 fetchUsers();
21 }, []);
22
23 const handleUserClick = (userId: number) => {
24 navigate(`/users/${userId}`);
25 };
26
27 return (
28 <div className="container mx-auto p-6">
29 <h1 className="text-3xl font-bold mb-6">All Users</h1>
30 <div className="grid gap-4">
31 {users.map((u) => (
32 <div
33 key={u.id}
34 onClick={() => handleUserClick(u.id)}
35 className="bg-white shadow-md rounded-lg p-4 hover:shadow-lg hover:bg-gray-50 cursor-pointer transition-all"
36 >
37 <h2 className="text-xl font-semibold">{u.fullName}</h2>
38 <p className="text-gray-600">@{u.username}</p>
39 <p className="text-gray-600">{u.id}</p>
40 </div>
41 ))}
42 </div>
43 </div>
44 );
45};
46
47export default AllUsers;
Note: See TracBrowser for help on using the repository browser.