| 1 | import { useState, useEffect } from "react";
|
|---|
| 2 |
|
|---|
| 3 | import { Link, useParams, useNavigate } from "react-router-dom";
|
|---|
| 4 | import axios from "axios";
|
|---|
| 5 | import NavbarKlasen from "../../../components/navbarKlasen/NavbarKlasen.jsx";
|
|---|
| 6 |
|
|---|
| 7 | const PredmetenNastavnik_StudentsView = () => {
|
|---|
| 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>
|
|---|
| 57 | <NavbarKlasen />
|
|---|
| 58 | <div>Вчитување на учениците...</div>
|
|---|
| 59 | </div>
|
|---|
| 60 | );
|
|---|
| 61 |
|
|---|
| 62 | return (
|
|---|
| 63 | <div>
|
|---|
| 64 | <div>
|
|---|
| 65 | <NavbarKlasen />
|
|---|
| 66 | <div className="navbar navbar-expand-lg bg-secondary justify-content-start ">
|
|---|
| 67 | <ul className="navbar-nav">
|
|---|
| 68 | <li className="nav-item active">
|
|---|
| 69 | <Link className="nav-link text-white fs-4">
|
|---|
| 70 | {" "}
|
|---|
| 71 | Соопштенија за класот{" "}
|
|---|
| 72 | </Link>
|
|---|
| 73 | </li>
|
|---|
| 74 |
|
|---|
| 75 | <li className="nav-item">
|
|---|
| 76 | <Link
|
|---|
| 77 | className="nav-link text-white fs-4"
|
|---|
| 78 | to={`/predmetenNastavnikDashboard/klas/${classId}/weeklyPlan`}
|
|---|
| 79 | >
|
|---|
| 80 | {" "}
|
|---|
| 81 | Неделни активности
|
|---|
| 82 | </Link>
|
|---|
| 83 | </li>
|
|---|
| 84 | <li className="nav-item">
|
|---|
| 85 | <Link
|
|---|
| 86 | className="nav-link text-white fs-4"
|
|---|
| 87 | to={`/predmetenNastavnikDashboard/klas/${classId}/schedule`}
|
|---|
| 88 | >
|
|---|
| 89 | {" "}
|
|---|
| 90 | Распоред
|
|---|
| 91 | </Link>
|
|---|
| 92 | </li>
|
|---|
| 93 | <li className="nav-item">
|
|---|
| 94 | <Link
|
|---|
| 95 | className="nav-link text-white fs-4"
|
|---|
| 96 | to={`/predmetenNastavnikDashboard/klas/${classId}/students`}
|
|---|
| 97 | >
|
|---|
| 98 | {" "}
|
|---|
| 99 | Студенти
|
|---|
| 100 | </Link>
|
|---|
| 101 | </li>
|
|---|
| 102 | <li className="nav-item">
|
|---|
| 103 | <Link
|
|---|
| 104 | className="nav-link text-white fs-4"
|
|---|
| 105 | to={`/predmetenNastavnikDashboard/klas/${classId}/subjects`}
|
|---|
| 106 | >
|
|---|
| 107 | {" "}
|
|---|
| 108 | Види слушани предмети
|
|---|
| 109 | </Link>
|
|---|
| 110 | </li>
|
|---|
| 111 | </ul>
|
|---|
| 112 | </div>
|
|---|
| 113 |
|
|---|
| 114 | <h1>Ученици</h1>
|
|---|
| 115 |
|
|---|
| 116 | <div>
|
|---|
| 117 | <table className="table table-striped">
|
|---|
| 118 | <thead>
|
|---|
| 119 | <tr>
|
|---|
| 120 | <th>Р. број</th>
|
|---|
| 121 | <th>Име</th>
|
|---|
| 122 | <th>Презиме</th>
|
|---|
| 123 | <th>Пол</th>
|
|---|
| 124 | <th>Старател</th>
|
|---|
| 125 | <th>Адреса</th>
|
|---|
| 126 | <th>Телефонски број</th>
|
|---|
| 127 | <th>Акции</th>
|
|---|
| 128 | </tr>
|
|---|
| 129 | </thead>
|
|---|
| 130 | <tbody>
|
|---|
| 131 | {students.map((student, index) => (
|
|---|
| 132 | <tr key={student.id}>
|
|---|
| 133 | <td>{index + 1}.</td>
|
|---|
| 134 | <td>{student.ime}</td>
|
|---|
| 135 | <td>{student.prezime}</td>
|
|---|
| 136 | <td>{student.pol === "Masko" ? "Машко" : "Женско"}</td>
|
|---|
| 137 | <td>
|
|---|
| 138 | {student.parentInfo
|
|---|
| 139 | ? `${student.parentInfo.ime} ${student.parentInfo.prezime}`
|
|---|
| 140 | : "Нема податок"}
|
|---|
| 141 | </td>
|
|---|
| 142 | <td>{student.adresa}</td>
|
|---|
| 143 | <td>{student.mobilenTelefon}</td>
|
|---|
| 144 | <td>
|
|---|
| 145 | {console.log(classId)}
|
|---|
| 146 | <button
|
|---|
| 147 | onClick={() =>
|
|---|
| 148 | navigate(
|
|---|
| 149 | `/predmetenNastavnikDashboard/klas/${classId}/student/${student.id}/grades`
|
|---|
| 150 | )
|
|---|
| 151 | }
|
|---|
| 152 | >
|
|---|
| 153 | види оценки
|
|---|
| 154 | </button>
|
|---|
| 155 | <button
|
|---|
| 156 | onClick={() =>
|
|---|
| 157 | navigate(
|
|---|
| 158 | `/predmetenNastavnikDashboard/klas/${classId}/student/${student.id}/attendance`
|
|---|
| 159 | )
|
|---|
| 160 | }
|
|---|
| 161 | >
|
|---|
| 162 | види присуства
|
|---|
| 163 | </button>
|
|---|
| 164 | </td>
|
|---|
| 165 | </tr>
|
|---|
| 166 | ))}
|
|---|
| 167 | </tbody>
|
|---|
| 168 | </table>
|
|---|
| 169 | {students.length === 0 && <p>Нема запишани ученици во овој клас.</p>}
|
|---|
| 170 | </div>
|
|---|
| 171 | </div>
|
|---|
| 172 | </div>
|
|---|
| 173 | );
|
|---|
| 174 | };
|
|---|
| 175 |
|
|---|
| 176 | export default PredmetenNastavnik_StudentsView;
|
|---|