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