| 1 | import React, { useState, useEffect } from "react";
|
|---|
| 2 | import axios from "axios";
|
|---|
| 3 | import { useParams, useNavigate } from "react-router-dom";
|
|---|
| 4 | import styles from "./AdminPanelNedelniAktivnostiZaKlasPageStyles.module.css";
|
|---|
| 5 | import Navbar from "../../../components/nav/Navbar.jsx";
|
|---|
| 6 |
|
|---|
| 7 | import { Link } from "react-router-dom";
|
|---|
| 8 | const AdminPanelNedelniAktivnostiZaKlasPage = () => {
|
|---|
| 9 | const { classId } = useParams();
|
|---|
| 10 | const navigate = useNavigate();
|
|---|
| 11 | const [plan, setPlan] = useState(null);
|
|---|
| 12 | const [classDetails, setClassDetails] = useState(null);
|
|---|
| 13 | const [loading, setLoading] = useState(true);
|
|---|
| 14 |
|
|---|
| 15 | const daysMapping = [
|
|---|
| 16 | { label: "Понеделник", key: "Ponedelnik" },
|
|---|
| 17 | { label: "Вторник", key: "Vtornik" },
|
|---|
| 18 | { label: "Среда", key: "Sreda" },
|
|---|
| 19 | { label: "Четврток", key: "Cetvrtok" },
|
|---|
| 20 | { label: "Петок", key: "Petok" },
|
|---|
| 21 | { label: "Сабота", key: "Sabota" },
|
|---|
| 22 | ];
|
|---|
| 23 |
|
|---|
| 24 | const nastavniCasovi = [1, 2, 3, 4, 5, 6, 7, 8];
|
|---|
| 25 |
|
|---|
| 26 | useEffect(() => {
|
|---|
| 27 | const fetchAllData = async () => {
|
|---|
| 28 | try {
|
|---|
| 29 | setLoading(true);
|
|---|
| 30 | const [resPlan, resClass] = await Promise.all([
|
|---|
| 31 | axios.get(`http://localhost:8080/api/klas/${classId}/nedelenPlan`, {
|
|---|
| 32 | withCredentials: true,
|
|---|
| 33 | }),
|
|---|
| 34 | axios.get(`http://localhost:8080/api/klas/${classId}`, {
|
|---|
| 35 | withCredentials: true,
|
|---|
| 36 | }),
|
|---|
| 37 | ]);
|
|---|
| 38 | setPlan(resPlan.data);
|
|---|
| 39 | setClassDetails(resClass.data);
|
|---|
| 40 | } catch (err) {
|
|---|
| 41 | console.error("Грешка при вчитување податоци:", err);
|
|---|
| 42 | } finally {
|
|---|
| 43 | setLoading(false);
|
|---|
| 44 | }
|
|---|
| 45 | };
|
|---|
| 46 | if (classId) fetchAllData();
|
|---|
| 47 | }, [classId]);
|
|---|
| 48 |
|
|---|
| 49 | if (loading)
|
|---|
| 50 | return (
|
|---|
| 51 | <div className={styles.wrapper}>
|
|---|
| 52 | <Navbar />
|
|---|
| 53 | <div className={styles.loaderContainer}>
|
|---|
| 54 | <h2>Вчитување на неделниот план...</h2>
|
|---|
| 55 | </div>
|
|---|
| 56 | </div>
|
|---|
| 57 | );
|
|---|
| 58 |
|
|---|
| 59 | return (
|
|---|
| 60 | <div className={styles.wrapper}>
|
|---|
| 61 | <Navbar />
|
|---|
| 62 | <div
|
|---|
| 63 | className="d-flex flex-row justify-content-center align-items-center p-2"
|
|---|
| 64 | style={{ backgroundColor: "#147176" }}
|
|---|
| 65 | >
|
|---|
| 66 | <Link
|
|---|
| 67 | to="/adminDashboard/users"
|
|---|
| 68 | className="mx-3 text-white text-decoration-none fs-6 opacity-100-hover"
|
|---|
| 69 | >
|
|---|
| 70 | Корисници
|
|---|
| 71 | </Link>
|
|---|
| 72 |
|
|---|
| 73 | <Link
|
|---|
| 74 | to="/adminDashboard/classes"
|
|---|
| 75 | className="mx-3 text-white text-decoration-none fs-6"
|
|---|
| 76 | >
|
|---|
| 77 | Класови
|
|---|
| 78 | </Link>
|
|---|
| 79 |
|
|---|
| 80 | <Link
|
|---|
| 81 | to="/adminDashboard/subjects"
|
|---|
| 82 | className="mx-3 text-white text-decoration-none fs-6"
|
|---|
| 83 | >
|
|---|
| 84 | Предмети
|
|---|
| 85 | </Link>
|
|---|
| 86 |
|
|---|
| 87 | <Link
|
|---|
| 88 | to="/adminDashboard/schedules"
|
|---|
| 89 | className="mx-3 text-white text-decoration-none fs-6"
|
|---|
| 90 | >
|
|---|
| 91 | Распореди
|
|---|
| 92 | </Link>
|
|---|
| 93 |
|
|---|
| 94 | <Link
|
|---|
| 95 | to="/adminDashboard/weeklyPlans"
|
|---|
| 96 | className="mx-3 text-white text-decoration-none fs-6"
|
|---|
| 97 | >
|
|---|
| 98 | Неделни планови
|
|---|
| 99 | </Link>
|
|---|
| 100 | </div>
|
|---|
| 101 | <div className={styles.contentContainer}>
|
|---|
| 102 | <h1 className={styles.title}>
|
|---|
| 103 | Клас {classDetails?.oddelenie}
|
|---|
| 104 | {classDetails?.paralelka} – Активности за тековната недела
|
|---|
| 105 | </h1>
|
|---|
| 106 |
|
|---|
| 107 | <p className={styles.dates}>
|
|---|
| 108 | {plan?.datumOd} – {plan?.datumDo}
|
|---|
| 109 | </p>
|
|---|
| 110 |
|
|---|
| 111 | <table className={styles.weeklyTable}>
|
|---|
| 112 | <thead>
|
|---|
| 113 | <tr>
|
|---|
| 114 | <th className={styles.hourCol}>Час</th>{" "}
|
|---|
| 115 | {daysMapping.map((day) => (
|
|---|
| 116 | <th key={day.key}>{day.label}</th>
|
|---|
| 117 | ))}
|
|---|
| 118 | </tr>
|
|---|
| 119 | </thead>
|
|---|
| 120 | <tbody>
|
|---|
| 121 | {nastavniCasovi.map((casBroj, rowIndex) => (
|
|---|
| 122 | <tr key={casBroj}>
|
|---|
| 123 | <td className={styles.hourCell}>{casBroj}</td>
|
|---|
| 124 | {daysMapping.map((day) => {
|
|---|
| 125 | const aktivnostiZaDenot = plan?.timetable?.[day.key] || [];
|
|---|
| 126 |
|
|---|
| 127 | const aktivnost = aktivnostiZaDenot[rowIndex];
|
|---|
| 128 |
|
|---|
| 129 | return (
|
|---|
| 130 | <td key={day.key} className={styles.tableCell}>
|
|---|
| 131 | {aktivnost ? (
|
|---|
| 132 | <div className={styles.activityBox}>
|
|---|
| 133 | <span className={styles.activityTitle}>
|
|---|
| 134 | <p>
|
|---|
| 135 | <b>Име на предмет:</b>
|
|---|
| 136 | </p>
|
|---|
| 137 |
|
|---|
| 138 | {aktivnost.naslov}
|
|---|
| 139 | </span>
|
|---|
| 140 |
|
|---|
| 141 | <p className={styles.activityDescription}>
|
|---|
| 142 | <br />
|
|---|
| 143 | <p>
|
|---|
| 144 | <b>Тема</b>
|
|---|
| 145 | </p>
|
|---|
| 146 | {aktivnost.opis}
|
|---|
| 147 | <br />
|
|---|
| 148 | </p>
|
|---|
| 149 | </div>
|
|---|
| 150 | ) : (
|
|---|
| 151 | <div className={styles.emptyCell}></div>
|
|---|
| 152 | )}
|
|---|
| 153 | </td>
|
|---|
| 154 | );
|
|---|
| 155 | })}
|
|---|
| 156 | </tr>
|
|---|
| 157 | ))}
|
|---|
| 158 | </tbody>
|
|---|
| 159 | </table>
|
|---|
| 160 | </div>
|
|---|
| 161 | </div>
|
|---|
| 162 | );
|
|---|
| 163 | };
|
|---|
| 164 |
|
|---|
| 165 | export default AdminPanelNedelniAktivnostiZaKlasPage;
|
|---|