source: frontend/web3-eDnevnik_Frontend/src/pages/dashboards/RoditelDashboard/RoditelDashboard.jsx

Last change on this file was 81cdf2d, checked in by Nikola Janev <nikolajanev57@…>, 9 days ago

initial commit

  • Property mode set to 100644
File size: 4.0 KB
Line 
1import React, { useState, useEffect } from "react";
2import axios from "axios";
3import { Link } from "react-router-dom";
4import NavbarRoditel from "../../../components/NavbarRoditel/NavbarRoditel";
5import styles from "../Klasen_RakovoditelDashboard/KlasenRakovoditelDashboardPageStyles.module.css";
6import RoditelSettings from "../../../components/RoditelSettings/RoditelSettings";
7import Roditel_PaymentAnnoucements from "../../RoditelPages/Roditel_PaymentAnnoucements/Roditel_PaymentAnnoucements";
8
9const RoditelDashboardViewPage = ({ parentId }) => {
10 const [ucenici, setUcenici] = useState([]);
11 const [error, setError] = useState("");
12 const [loading, setLoading] = useState(true);
13 const [connectedWallet, setConnectedWallet] = useState(null);
14 const [roditelId, setRoditelId] = useState(null);
15
16 useEffect(() => {
17 const fetchRoditelId = async () => {
18 try {
19 const response = await fetch("http://localhost:8080/api/auth/me", {
20 credentials: "include",
21 });
22 const data = await response.json();
23 setRoditelId(data.id);
24 } catch (err) {
25 console.error("Error fetching roditel ID:", err);
26 }
27 };
28
29 fetchRoditelId();
30 }, []);
31
32 useEffect(() => {
33 const initializeDashboard = async () => {
34 if (!parentId) return;
35 try {
36 setLoading(true);
37 const resUcenici = await axios.get(
38 `http://localhost:8080/api/users/ucenici/by-parent/${parentId}`,
39 { withCredentials: true }
40 );
41 setUcenici(resUcenici.data);
42 } catch (err) {
43 console.log(err);
44 } finally {
45 setLoading(false);
46 }
47 };
48 initializeDashboard();
49 }, [parentId]);
50
51 if (loading)
52 return (
53 <div className={styles.loader}>
54 Вчитување на податоци за вашето дете...
55 </div>
56 );
57
58 return (
59 <>
60 <div>
61 <NavbarRoditel />
62 <div className="container mt-5 mh-100">
63 <div className="row">
64 <div className="col-12">
65 <nav
66 className="text-white d-flex flex-row gap-3 p-3"
67 style={{ backgroundColor: "#147176" }}
68 >
69 <div className="dropdown">
70 <button
71 className="btn btn-secondary dropdown-toggle"
72 type="button"
73 id="dropdownMenuButton"
74 data-bs-toggle="dropdown"
75 aria-haspopup="true"
76 aria-expanded="false"
77 >
78 Мои деца
79 </button>
80 <div
81 className="dropdown-menu"
82 aria-labelledby="dropdownMenuButton"
83 >
84 {loading ? (
85 <div className="dropdown-item">Вчитување...</div>
86 ) : ucenici.length > 0 ? (
87 ucenici.map((k) => (
88 <Link
89 key={k.id}
90 className="dropdown-item"
91 to={`/roditelDashboard/ucenik/${k.id}/soopstenija`}
92 >
93 {k.ime} {k.prezime}
94 </Link>
95 ))
96 ) : (
97 <div className="dropdown-item">Нема Ученици</div>
98 )}
99 </div>
100 </div>
101 <Link
102 className="btn btn-secondary"
103 to="/roditelDashboard/paymentAnnoucements"
104 >
105 Соопштенија за плаќање{" "}
106 </Link>
107 <Link
108 className="btn btn-secondary"
109 to="/roditelDashboard/myPayments"
110 >
111 Мои плаќања
112 </Link>
113 </nav>
114 </div>
115 </div>
116 </div>
117 </div>
118 </>
119 );
120};
121
122export default RoditelDashboardViewPage;
Note: See TracBrowser for help on using the repository browser.