Se conectó la visualización

This commit is contained in:
evenegas
2025-06-18 12:56:42 -06:00
parent 3817e7bd4b
commit cd74bf14be
2 changed files with 24 additions and 31 deletions
+3 -1
View File
@@ -37,7 +37,9 @@ export default function Dashboard() {
});
if (!response.ok) {
throw new Error("Error al descargar la base de datos");
const errorBody = await response.json();
alert(`Error al descargar: ${errorBody.message}`);
return;
}
const blob = await response.blob();
+21 -30
View File
@@ -1,9 +1,6 @@
"use client";
import React, { useState } from "react";
import axios from "axios";
import Select from "@/components/select";
import Input from "@/components/input";
import Button from "@/components/button";
@@ -15,23 +12,29 @@ export default function Dashboard() {
const [error, setError] = useState('');
const handleSubmit = async () => {
if (!value) {
setError("Ingresa un número de cuenta válido");
return;
}
setLoading(true);
setError('');
setResultados([]);
try {
const response = await axios.get(`/api/usuarios`, {
params: {
tipo,
cuenta: value,
},
});
setResultados(response.data);
const res = await fetch(`http://localhost:4000/usuarios/${value}`);
if (!res.ok) {
const errData = await res.json();
throw new Error(errData.message || "Error al consultar usuario");
}
const data = await res.json();
setResultados(data);
} catch (err: any) {
const message =
err.response?.data?.message ||
err.message ||
'Error al iniciar sesión';
const message = err.message || "Error desconocido";
setError(message);
console.error("Error al obtener datos:", error);
setResultados([]);
console.error("Error al obtener datos:", err);
} finally {
setLoading(false);
}
@@ -73,19 +76,6 @@ export default function Dashboard() {
>
<h2 className="text-xl font-semibold mb-4">Visualización De Datos</h2>
<Select
label="Tipo de Usuario"
name="usuario"
placeholder="Selecciona un usuario"
options={[
{ value: "mx", label: "México" },
{ value: "us", label: "Estados Unidos" },
{ value: "ca", label: "Canadá" },
]}
value={tipo}
onChange={(e) => setTipo(e.target.value)}
/>
<Input
label="No.Cuenta"
placeholder="Ingresa tu No.Cuenta"
@@ -98,10 +88,11 @@ export default function Dashboard() {
</Button>
</div>
</div>
{error && (
<p style={{ color: "red", marginTop: "0.5rem", textAlign: "center" }}>{error}</p>
)}
{/* Resultados */}
{resultados.length > 0 && (
<table
style={{