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