From ed76be8351a264ff456e692d6d1d11e688d480d2 Mon Sep 17 00:00:00 2001 From: Sergio Nicolas Lavaise Date: Thu, 23 Apr 2026 23:58:59 -0300 Subject: [PATCH] =?UTF-8?q?Fix:=20carga=20=C3=A1reas=20en=20modal=20de=20e?= =?UTF-8?q?dici=C3=B3n=20de=20usuarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Agrega endpoint GET /api/areas en servidor - Carga áreas desde API en GestionUsuarios en lugar de usar store --- server/index.js | 10 ++++++++++ src/sections/GestionUsuarios.tsx | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/server/index.js b/server/index.js index f25b38d..c81a12d 100644 --- a/server/index.js +++ b/server/index.js @@ -254,6 +254,16 @@ app.put('/api/auth/update-email', async (req, res) => { // === GESTIÓN DE USUARIOS (ADMIN) === +app.get('/api/areas', async (req, res) => { + try { + const areas = await getAllAreas(); + res.json(areas); + } catch (err) { + console.error(err); + res.status(500).json({ error: 'Error al obtener áreas' }); + } +}); + app.get('/api/usuarios', async (req, res) => { try { const usuarios = await getAllUsuarios(); diff --git a/src/sections/GestionUsuarios.tsx b/src/sections/GestionUsuarios.tsx index b6d0501..fc98f98 100644 --- a/src/sections/GestionUsuarios.tsx +++ b/src/sections/GestionUsuarios.tsx @@ -1,6 +1,6 @@ import { useState, useEffect } from 'react'; import { useHospitalStore } from '@/hooks/useHospitalStore'; -import type { Usuario, RolUsuario } from '@/types'; +import type { Usuario, RolUsuario, Area } from '@/types'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -14,8 +14,9 @@ import { Plus, Pencil, Trash2, UserCog, Mail, Shield } from 'lucide-react'; const API_BASE = 'http://localhost:4001/api'; export function GestionUsuarios() { - const { logout, areas } = useHospitalStore(); + const { logout } = useHospitalStore(); const [usuarios, setUsuarios] = useState([]); + const [areas, setAreas] = useState([]); const [loading, setLoading] = useState(true); const [dialogOpen, setDialogOpen] = useState(false); const [editUsuario, setEditUsuario] = useState(null); @@ -34,6 +35,7 @@ export function GestionUsuarios() { useEffect(() => { fetchUsuarios(); + fetchAreas(); }, []); const fetchUsuarios = async () => { @@ -48,6 +50,16 @@ export function GestionUsuarios() { } }; + const fetchAreas = async () => { + try { + const res = await fetch(`${API_BASE}/areas`); + const data = await res.json(); + setAreas(data); + } catch (err) { + console.error(err); + } + }; + const resetForm = () => { setForm({ apellido: '',