import React, { useState, useEffect } from "react"; import axios from "axios"; import styles from "../Klasen_RakovoditelDashboard/KlasenRakovoditelDashboardPageStyles.module.css"; import NavbarKlasen from "../../../components/navbarKlasen/NavbarKlasen.jsx"; import { Link } from "react-router-dom"; const KlasenRakovoditelDashboardViewPage = ({ teacherId }) => { const [classId, setClassId] = useState(null); const [classInfo, setClassInfo] = useState(null); const [klasen, setKlasen] = useState(null); const [students, setStudents] = useState([]); const [soopstenija, setSoopstenija] = useState([]); const [loading, setLoading] = useState(true); const [parents, setParents] = useState([]); useEffect(() => { const initializeDashboard = async () => { if (!teacherId) return; try { setLoading(true); const resClassInitial = await axios.get( `http://localhost:8080/api/users/nastavnici/klasniRakovoditeli/${teacherId}/klas`, { withCredentials: true } ); const foundClass = resClassInitial.data; if (foundClass?.id) { const cId = foundClass.id; setClassId(cId); const resStudents = await axios.get( `http://localhost:8080/api/klas/${cId}/students`, { withCredentials: true, } ); const studentsData = resStudents.data; setStudents(studentsData); const parentIds = [ ...new Set( studentsData.map((s) => s.staratelId).filter((id) => id) ), ]; const parentRequests = parentIds.map((id) => axios.get(`http://localhost:8080/api/users/roditeli/${id}`, { withCredentials: true, }) ); const parentResponses = await Promise.all(parentRequests); const parentsData = parentResponses.map((res) => res.data); setParents(parentsData); const [resClass, resKlasen, resSoopstenija] = await Promise.all([ axios.get(`http://localhost:8080/api/klas/${cId}`, { withCredentials: true, }), axios.get( `http://localhost:8080/api/klas/${cId}/klasenRakovoditel`, { withCredentials: true } ), axios.get(`http://localhost:8080/api/klas/${cId}/soopstenija`, { withCredentials: true, }), ]); setClassInfo(resClass.data); setKlasen(resKlasen.data); setStudents(resStudents.data); setSoopstenija(resSoopstenija.data); } } catch (err) { console.error("Грешка при иницијализација:", err); } finally { setLoading(false); } }; initializeDashboard(); }, [teacherId]); const formatDate = (dateString) => { if (!dateString) return ""; return new Date(dateString).toLocaleDateString("mk-MK"); }; if (loading) return
{s.sodrzina}
Отстрани соопштениеНема активни соопштенија.
)}{klasen ? `${klasen.ime} ${klasen.prezime}` : "Не е назначен"}