| 1 | import React, { useState, useEffect } from "react";
|
|---|
| 2 | import axios from "axios";
|
|---|
| 3 | import { useParams } from "react-router-dom";
|
|---|
| 4 | import { Link,useNavigate } from "react-router-dom";
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | import NavbarKlasen from "../../../components/navbarKlasen/NavbarKlasen.jsx";
|
|---|
| 8 |
|
|---|
| 9 | const PredmetenNastavnik_PrisustvaZaStudentView = () => {
|
|---|
| 10 | const [studentData, setStudentData] = useState(null);
|
|---|
| 11 | const { studentId } = useParams();
|
|---|
| 12 | const [loading, setLoading] = useState(true);
|
|---|
| 13 | const [error, setError] = useState(null);
|
|---|
| 14 | const navigate = useNavigate();
|
|---|
| 15 | const [classId, setClassId] = useState(null)
|
|---|
| 16 |
|
|---|
| 17 | useEffect(() => {
|
|---|
| 18 | const fetchData = async () => {
|
|---|
| 19 | try {
|
|---|
| 20 | setLoading(true);
|
|---|
| 21 |
|
|---|
| 22 | const res = await axios.get(
|
|---|
| 23 | `http://localhost:8080/api/users/ucenici/${studentId}/prisustva`,
|
|---|
| 24 | { withCredentials: true }
|
|---|
| 25 | );
|
|---|
| 26 | console.log(JSON.stringify(res.data.classId, null, 2));
|
|---|
| 27 | setStudentData(res.data);
|
|---|
| 28 | setClassId(res.data.classId)
|
|---|
| 29 | } catch (err) {
|
|---|
| 30 | setError("Грешка при вчитување");
|
|---|
| 31 | console.error(err);
|
|---|
| 32 | } finally {
|
|---|
| 33 | setLoading(false);
|
|---|
| 34 | }
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | if (studentId) fetchData();
|
|---|
| 38 | }, [studentId]);
|
|---|
| 39 |
|
|---|
| 40 | if (loading) return <div>Вчитување...</div>;
|
|---|
| 41 |
|
|---|
| 42 | if (error) return <div>{error}</div>;
|
|---|
| 43 |
|
|---|
| 44 | const handleVnesiPrisustvo = () => {
|
|---|
| 45 |
|
|---|
| 46 | navigate(
|
|---|
| 47 | `/predmetenNastavnikDashboard/klas/${classId}/student/${studentId}/attendance/insertPrisustvo`
|
|---|
| 48 | );
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | return (
|
|---|
| 53 | <div>
|
|---|
| 54 | <NavbarKlasen />
|
|---|
| 55 |
|
|---|
| 56 | <main>
|
|---|
| 57 | <header>
|
|---|
| 58 | <h1>
|
|---|
| 59 | Преглед на присуства за {studentData.ime} {studentData.prezime}
|
|---|
| 60 | </h1>
|
|---|
| 61 |
|
|---|
| 62 | </header>
|
|---|
| 63 |
|
|---|
| 64 | <div>
|
|---|
| 65 | <button onClick={handleVnesiPrisustvo} className="btn btn-primary m-3">Внеси забелешка за присуство</button>
|
|---|
| 66 | <table className="table table-striped">
|
|---|
| 67 | <thead>
|
|---|
| 68 | <tr>
|
|---|
| 69 | <th>Датум</th>
|
|---|
| 70 | <th>Статус</th>
|
|---|
| 71 | <th>Забелешка</th>
|
|---|
| 72 | <th>Евидентирано од</th>
|
|---|
| 73 | <th>За часот</th>
|
|---|
| 74 | </tr>
|
|---|
| 75 | </thead>
|
|---|
| 76 |
|
|---|
| 77 | <tbody>
|
|---|
| 78 | {studentData.prisustva?.length > 0 ? (
|
|---|
| 79 | studentData.prisustva.map((p) => (
|
|---|
| 80 |
|
|---|
| 81 | <tr key={p.id}>
|
|---|
| 82 | <td>{new Date(p.datum).toLocaleDateString("mk-MK")}</td>
|
|---|
| 83 |
|
|---|
| 84 | <td>
|
|---|
| 85 | <span>{p.status}</span>
|
|---|
| 86 | </td>
|
|---|
| 87 |
|
|---|
| 88 | <td>{p.zabeleska || "—"}</td>
|
|---|
| 89 |
|
|---|
| 90 | <td>
|
|---|
| 91 | {p.nastavnik.ime} {p.nastavnik.prezime}
|
|---|
| 92 | </td>
|
|---|
| 93 |
|
|---|
| 94 | <td>
|
|---|
| 95 |
|
|---|
| 96 | {p.cas.ime} во {p.cas.denVo_Nedelata} со реден час{" "}
|
|---|
| 97 | {p.cas.reden_cas}
|
|---|
| 98 | </td>
|
|---|
| 99 | </tr>
|
|---|
| 100 | ))
|
|---|
| 101 | ) : (
|
|---|
| 102 | <tr>
|
|---|
| 103 | <td colSpan="5">Нема евидентирано присуства.</td>
|
|---|
| 104 | </tr>
|
|---|
| 105 | )}
|
|---|
| 106 | </tbody>
|
|---|
| 107 | </table>
|
|---|
| 108 | </div>
|
|---|
| 109 | </main>
|
|---|
| 110 | </div>
|
|---|
| 111 | );
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | export default PredmetenNastavnik_PrisustvaZaStudentView;
|
|---|