Skip to content

Commit f6a5b71

Browse files
authored
Merge pull request #5 from AnderssonProgramming/fix/implement_login_insights
Fix and Restructure Insights Page Implementation for Admin View
2 parents f0ef652 + 4f21fb9 commit f6a5b71

25 files changed

+11864
-9876
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Durante el desarrollo del proyecto, se utilizaron las siguientes librerías:
5454
```sh
5555
npm install react-router-dom
5656
npm install axios
57+
npm install d3
5758
```
5859

5960
## MANTENIMIENTO Y CONSTRUCCIÓN

package-lock.json

Lines changed: 11275 additions & 8748 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ ul {
9898
height: 20%;
9999
}
100100

101-
.content .panel .header .title {
101+
.content .panel .header .info {
102+
display: flex;
103+
flex-direction: column;
104+
gap: 5px;
105+
}
106+
107+
.content .panel .header .info .title {
102108
font-weight: bold;
103109
}
104110

105-
.content .panel .header .title, .content .panel .header .greetings {
111+
.content .panel .header .info .title, .content .panel .header .greetings {
106112
font-size: 21px;
107113
}
108114

src/App.js

Lines changed: 145 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,163 @@
11
import React, { useState, useEffect } from "react";
2-
import { BrowserRouter as Router, Route, Routes, Navigate } from "react-router-dom";
2+
import {
3+
BrowserRouter as Router,
4+
Route,
5+
Routes,
6+
Link,
7+
useLocation,
8+
Navigate
9+
} from "react-router-dom";
10+
import { ReactComponent as House } from './assets/icons/house-user_11269953 1.svg';
11+
import { ReactComponent as Room } from './assets/icons/workshop_14672030 1.svg';
12+
import { ReactComponent as User } from './assets/icons/User.svg';
313
import Home from './pages/Home/Home.js';
414
import LoginPage from './pages/Login/LoginPage.jsx';
5-
import AdministratorHome from './pages/Administrator/AdministratorHome.jsx'; // Importa el componente
6-
15+
import AdministratorHome from './pages/Administrator/AdministratorHome.jsx';
716
import './App.css';
817

18+
/**
19+
* Configuración de rutas según el rol del usuario.
20+
*/
21+
const routesConfig = {
22+
admin: [
23+
{ path: "/administrador", name: "Panel de Control", icon: <House className="svg" /> },
24+
{ path: "/administrador/salones", name: "Gestión de Salones", icon: <Room className="svg" /> },
25+
{ path: "/administrador/usuarios", name: "Gestión de Usuarios", icon: <User className="svg" /> },
26+
],
27+
profe: [
28+
{ path: "/home", name: "Gestión de Reservas", icon: <House className="svg" /> },
29+
],
30+
};
31+
32+
const Menu = ({ user }) => {
33+
if (!user) return null;
34+
return (
35+
<ul className="menu">
36+
{routesConfig[(user.isAdmin ? "admin" : "profe")]?.map((item, index) => (
37+
<li className="item-menu" key={index}>
38+
<Link className="navBarBTN" to={item.path}>
39+
{item.icon}
40+
{item.name}
41+
</Link>
42+
</li>
43+
))}
44+
</ul>
45+
);
46+
};
47+
48+
/**
49+
* Componente de encabezado que muestra el título de la página y el saludo al usuario.
50+
*/
51+
const Header = ({ user }) => {
52+
const location = useLocation();
53+
let title = "Elysium";
54+
55+
if (user) {
56+
const currentPage = routesConfig[(user.isAdmin ? "admin" : "profe")]?.find(
57+
(route) => route.path === location.pathname
58+
);
59+
title = currentPage ? currentPage.name : "Elysium";
60+
}
61+
62+
useEffect(() => {
63+
document.title = title;
64+
}, [title]);
65+
66+
if (!user) return null;
67+
68+
return (
69+
<div className="header">
70+
<div className="info">
71+
<span className="title">{title}</span>
72+
<span className="greetings">
73+
Buen día, {user.isAdmin ? "Admin" : "Profe"} {user.nombre}
74+
</span>
75+
<span className="subtitle">
76+
Gestiona las reservas que has agendado últimamente
77+
</span>
78+
</div>
79+
<div className="user-info">
80+
81+
</div>
82+
</div>
83+
);
84+
};
85+
86+
/**
87+
* Componente principal de la aplicación.
88+
*/
989
function App() {
10-
const [role, setRole] = useState("");
90+
const [user, setUser] = useState(null);
91+
const [loading, setLoading] = useState(true);
1192

1293
useEffect(() => {
13-
// Aquí puedes manejar el rol del usuario tras login; por ejemplo, obtenerlo desde el token.
14-
// Para este ejemplo simulamos un rol admin.
15-
setRole("admin");
94+
const simulacionData = {
95+
"idInstitucional": 12,
96+
"nombre": "Santi",
97+
"apellido": "Castroso",
98+
"correoInstitucional": "[email protected]",
99+
"activo": true,
100+
"isAdmin": true,
101+
"password": null
102+
}
103+
setUser(simulacionData);
104+
setLoading(false);
16105
}, []);
17106

107+
useEffect(() => {
108+
if (user != null) {
109+
const colorVariable = user.isAdmin
110+
? "var(--variable-collection-user-admin)"
111+
: "var(--variable-collection-user-estandar)";
112+
document.documentElement.style.setProperty(
113+
"--variable-collection-current-color",
114+
colorVariable
115+
);
116+
}
117+
}, [user]);
118+
119+
if (loading) return <div>Cargando...</div>;
120+
18121
return (
19122
<Router>
20123
<Routes>
21-
<Route path="/" element={<LoginPage />} />
22-
<Route path="/adminhome" element={<AdministratorHome />} />
23-
<Route path="/home" element={<Home />} />
24-
{/* Resto de rutas */}
25-
{/* Si no hay coincidencia, redirigir a login */}
26-
<Route path="*" element={<Navigate to="/" replace />} />
124+
{!user ? (
125+
<>
126+
<Route path="/" element={<LoginPage onLogin={setUser} />} />
127+
<Route path="*" element={<Navigate to="/" />} />
128+
</>
129+
) : (
130+
<Route path="/*" element={
131+
<div className="content">
132+
<div className="navBar">
133+
<Menu user={user} />
134+
</div>
135+
<div className="panel">
136+
<Header user={user} />
137+
<div className="container">
138+
<Routes>
139+
{user.isAdmin ? (
140+
<>
141+
<Route path="/administrador" element={<AdministratorHome />} />
142+
<Route path="/administrador/salones" element={<div>Gestión de Salones</div>} />
143+
<Route path="/administrador/usuarios" element={<div>Gestión de Usuarios</div>} />
144+
<Route path="*" element={<Navigate to="/administrador" />} />
145+
</>
146+
) : (
147+
<>
148+
<Route path="/home" element={<Home />} />
149+
<Route path="*" element={<Navigate to="/home" />} />
150+
</>
151+
)}
152+
</Routes>
153+
</div>
154+
</div>
155+
</div>
156+
}/>
157+
)}
27158
</Routes>
28159
</Router>
29160
);
30161
}
31162

32-
export default App;
163+
export default App;

src/components/Admin/Header.jsx

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/components/Admin/Sidebar.jsx

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)