source: frontend/web3-eDnevnik_Frontend/src/pages/KlasenRakovoditel_Pages/Klasen_ViewStudentsInClass/Klasen_ViewStudentsInClass.jsx

Last change on this file was 81cdf2d, checked in by Nikola Janev <nikolajanev57@…>, 9 days ago

initial commit

  • Property mode set to 100644
File size: 5.3 KB
Line 
1import { useState, useEffect } from "react";
2import styles from "./Klasen_ViewStudentsInClassStyles.module.css";
3import { Link, useParams, useNavigate } from "react-router-dom";
4import axios from "axios";
5import NavbarKlasen from "../../../components/navbarKlasen/NavbarKlasen.jsx";
6
7const Klasen_ViewStudentsInClass = () => {
8 const { classId } = useParams();
9 const navigate = useNavigate();
10 const [students, setStudents] = useState([]);
11 const [loading, setLoading] = useState(true);
12
13 useEffect(() => {
14 const fetchStudentsAndParents = async () => {
15 try {
16 setLoading(true);
17
18 const response = await axios.get(
19 `http://localhost:8080/api/klas/${classId}/students`,
20 { withCredentials: true }
21 );
22 const studentsData = response.data;
23
24 const studentsWithParents = await Promise.all(
25 studentsData.map(async (student) => {
26 if (student.staratelId) {
27 try {
28 const parentRes = await axios.get(
29 `http://localhost:8080/api/users/roditeli/${student.staratelId}`,
30 { withCredentials: true }
31 );
32
33 return { ...student, parentInfo: parentRes.data };
34 } catch (err) {
35 console.error(`Грешка за родител ${student.staratelId}:`, err);
36 return { ...student, parentInfo: null };
37 }
38 }
39 return { ...student, parentInfo: null };
40 })
41 );
42
43 setStudents(studentsWithParents);
44 } catch (err) {
45 console.error("Грешка при вчитување податоци:", err);
46 } finally {
47 setLoading(false);
48 }
49 };
50
51 if (classId) fetchStudentsAndParents();
52 }, [classId]);
53
54 if (loading)
55 return (
56 <div className={styles.wrapper}>
57 <NavbarKlasen />
58 <div className={styles.loader}>Вчитување на учениците...</div>
59 </div>
60 );
61
62 return (
63 <div className="container-fluid m-0 p-0">
64 <div>
65 <NavbarKlasen />
66 <div className="container bg-success d-flex flex-row justify-content-flex-start">
67 <Link
68 to={`/dashboard`}
69 className="text-white m-3 fs-5 text-decoration-none"
70 >
71 Соопштение
72 </Link>
73 <Link
74 to={`/klasenRakovoditelDashboard/${classId}/weeklyPlan`}
75 className="text-white m-3 fs-5 text-decoration-none"
76 >
77 Види неделни активности
78 </Link>
79 <Link
80 to={`/klasenRakovoditelDashboard/${classId}/raspored`}
81 className="text-white m-3 fs-5 text-decoration-none"
82 >
83 Види распоред
84 </Link>
85 <Link
86 to={`/klasenRakovoditelDashboard/${classId}/students`}
87 className="text-white m-3 fs-5 text-decoration-underline"
88 >
89 Студенти
90 </Link>
91 </div>
92
93 <h1 className="m-3 text">Ученици</h1>
94
95 <div className={styles.tableContainer}>
96 <table className={styles.studentTable}>
97 <thead>
98 <tr>
99 <th>Р. број</th>
100 <th>Име</th>
101 <th>Презиме</th>
102 <th>Пол</th>
103 <th>Старател</th>
104 <th>Адреса</th>
105 <th>Телефонски број</th>
106 <th>Акции</th>
107 </tr>
108 </thead>
109 <tbody>
110 {students.map((student, index) => (
111 <tr key={student.id}>
112 <td>{index + 1}.</td>
113 <td>{student.ime}</td>
114 <td>{student.prezime}</td>
115 <td>{student.pol === "Masko" ? "Машко" : "Женско"}</td>
116 <td>
117 {student.parentInfo
118 ? `${student.parentInfo.ime} ${student.parentInfo.prezime}`
119 : "Нема податок"}
120 </td>
121 <td>{student.adresa}</td>
122 <td>{student.mobilenTelefon}</td>
123 <td>
124 <button
125 className="btn btn-primary me-3"
126 onClick={() =>
127 navigate(
128 `/klasenRakovoditelDashboard/${classId}/student/${student.id}/grades`
129 )
130 }
131 >
132 види оценки
133 </button>
134 <button
135 className="btn btn-secondary"
136 onClick={() =>
137 navigate(
138 `/klasenRakovoditelDashboard/${classId}/student/${student.id}/attendance`
139 )
140 }
141 >
142 види присуства
143 </button>
144 </td>
145 </tr>
146 ))}
147 </tbody>
148 </table>
149 {students.length === 0 && (
150 <p className={styles.noData}>Нема запишани ученици во овој клас.</p>
151 )}
152 </div>
153 </div>
154 </div>
155 );
156};
157
158export default Klasen_ViewStudentsInClass;
Note: See TracBrowser for help on using the repository browser.