Se afinaron detalles y se agregó la página de visualizacion

This commit is contained in:
evenegas
2025-06-13 15:12:59 -06:00
parent 877fcfe81e
commit 30944dee62
8 changed files with 689 additions and 66 deletions
+280
View File
@@ -8,6 +8,7 @@
"name": "carga_descarga_front",
"version": "0.1.0",
"dependencies": {
"axios": "^1.9.0",
"bootstrap": "^5.3.6",
"bootstrap-icons": "^1.13.1",
"next": "15.3.3",
@@ -642,6 +643,23 @@
"node": ">= 8"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT"
},
"node_modules/axios": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/binary-extensions": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
@@ -714,6 +732,19 @@
"node": ">=10.16.0"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001722",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001722.tgz",
@@ -810,6 +841,18 @@
"simple-swizzle": "^0.2.2"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"license": "MIT",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/csstype": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
@@ -817,6 +860,15 @@
"dev": true,
"license": "MIT"
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"license": "MIT",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/detect-libc": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.4.tgz",
@@ -827,6 +879,65 @@
"node": ">=8"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-set-tostringtag": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/fill-range": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
@@ -840,6 +951,42 @@
"node": ">=8"
}
},
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"license": "MIT",
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.3.tgz",
"integrity": "sha512-qsITQPfmvMOSAdeyZ+12I1c+CKSstAFAwu+97zrnWAbIr5u8wfsExUzCesVLC8NgHuRUqNN4Zy6UPWUTRGslcA==",
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"hasown": "^2.0.2",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@@ -855,6 +1002,52 @@
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/glob-parent": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
@@ -868,6 +1061,57 @@
"node": ">= 6"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-tostringtag": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
"license": "MIT",
"dependencies": {
"has-symbols": "^1.0.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/is-arrayish": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",
@@ -921,6 +1165,36 @@
"node": ">=0.12.0"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/nanoid": {
"version": "3.3.11",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz",
@@ -1050,6 +1324,12 @@
"node": "^10 || ^12 || >=14"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/react": {
"version": "19.1.0",
"resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz",
+1
View File
@@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"axios": "^1.9.0",
"bootstrap": "^5.3.6",
"bootstrap-icons": "^1.13.1",
"next": "15.3.3",
+39 -28
View File
@@ -4,6 +4,7 @@ import React from "react";
import FuenteCard from "@/components/fuenteCard";
import CargaArchivo from "@/components/cargaArchivo";
import Button from "@/components/button";
import { useAuthRedirect } from "@/hooks/auth";
const fuentes = [
{ nombre: "Fuente 1", fecha: "Martes 3 de mayo 2025", activa: true },
@@ -13,51 +14,61 @@ const fuentes = [
];
export default function Dashboard() {
// const loading = useAuthRedirect();
// if (loading) {
// return <p></p>;
// }
return (
<main className="p-6" style={{
minHeight: "100vh",
<main className="roboto" style={{
minHeight: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
background: "#063970"}}>
background: "#063970"
}}>
<div className="flex gap-4 flex-wrap mb-6" style={{
background: "#f3f4f6",
padding: "2rem",
borderRadius: "8px",
boxShadow: "0 4px 6px rgba(253, 253, 253, 0.1)",
width: "100%",
}}>
<Button onClick={() => alert('¡Hola mundo!')} className='mb-3'>
descarga Base de datos
</Button>
}}>
<h2 className="text-xl font-semibold mb-4">Fuentes</h2>
<div
style={{
<div
style={{
display: "flex",
flexDirection: "row",
justifyContent: "center",
gap: "16px", // espacio entre las cajas
}}>
{fuentes.map((f, idx) => (
<FuenteCard
key={idx}
nombre={f.nombre}
fecha={f.fecha}
activa={f.activa}
/>
))}
</div>
<h2 className="text-xl font-semibold mb-4">Carga</h2>
<div>
<CargaArchivo />
</div>
gap: "16px",
}}>
{fuentes.map((f, idx) => (
<FuenteCard
key={idx}
nombre={f.nombre}
fecha={f.fecha}
activa={f.activa}
/>
))}
</div>
<h2 className="text-xl font-semibold mb-4">Carga</h2>
<div>
<CargaArchivo />
</div>
<h2 className="text-xl font-semibold mb-4"> Descarga de Datos</h2>
<Button onClick={() => alert('¡Hola mundo!')} className='mb-3'>
Descarga Base de Datos
</Button>
</div>
</main>
);
}
+93 -38
View File
@@ -3,12 +3,36 @@
import Input from "@/components/input";
import PasswordInput from "@/components/password";
import { useState } from "react";
import axios from "axios";
import { useRouter } from "next/navigation";
export default function Login() {
const [value, setValue] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const router = useRouter();
const handleLogin = async () => {
try {
const response = await axios.post('/api/auth/login', {
cuenta: value,
password: password,
});
const token = response.data.token;
localStorage.setItem('token', token);
// Redirige al usuario
window.location.href = '/carga';
} catch (err: any) {
const message =
err.response?.data?.message ||
err.message ||
'Error al iniciar sesión';
setError(message);
}
};
return (
<main style={{
@@ -19,7 +43,6 @@ export default function Login() {
background: "#063970"
}}>
<div style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
@@ -28,47 +51,79 @@ export default function Login() {
borderRadius: "8px",
boxShadow: "0 4px 6px rgba(253, 253, 253, 0.1)",
width: "100%",
}}>
<div style={{
background: "#f3f4f6",
padding: "2rem",
borderRadius: "8px",
boxShadow: "0 4px 6px rgba(253, 253, 253, 0.1)",
width: "100%",
maxWidth: "400px",
}}><h2 style={{ color: "#fbbf24", textAlign: "center", marginBottom: "0.25rem" }}>Inicio de sesión</h2>
<h1 style={{ color: "#1e3a8a", textAlign: "center", fontWeight: "bold", marginBottom: "2rem" }}>Sistema de --------</h1>
background: "#f3f4f6",
padding: "2rem",
borderRadius: "8px",
boxShadow: "0 4px 6px rgba(253, 253, 253, 0.1)",
width: "100%",
maxWidth: "400px",
}}>
<h2 style={{ color: "#fbbf24", textAlign: "center", marginBottom: "0.25rem" }}>Inicio de sesión</h2>
<h1 style={{ color: "#1e3a8a", textAlign: "center", fontWeight: "bold", marginBottom: "2rem" }}>Sistema de --------</h1>
<Input
label="Número de cuenta"
placeholder="9 dígitos sin guión"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
<Input
label="Número de cuenta"
placeholder="9 dígitos sin guión"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
<PasswordInput
label="Contraseña"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<PasswordInput
label="Contraseña"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<button
type="submit"
style={{
width: "100%",
padding: "0.5rem",
backgroundColor: "#2563eb",
color: "#fff",
fontWeight: "bold",
border: "none",
borderRadius: "4px",
cursor: "pointer"
}}
>
Iniciar Sesión
</button></div>
{error && (
<p style={{ color: "red", marginTop: "0.5rem", textAlign: "center" }}>{error}</p>
)}
<div style={{
display: "flex",
flexDirection: "row",
justifyContent: "center",
gap: "16px",
}}>
<button
type="button"
onClick={handleLogin}
style={{
width: "100%",
padding: "0.5rem",
marginTop: "1rem",
backgroundColor: "#2563eb",
color: "#fff",
fontWeight: "bold",
border: "none",
borderRadius: "4px",
cursor: "pointer"
}}
>
Iniciar Sesión
</button>
<button
type="button"
onClick={() => router.replace("/visualizacion")}
style={{
width: "100%",
padding: "0.5rem",
marginTop: "1rem",
backgroundColor: "#009939",
color: "#fff",
fontWeight: "bold",
border: "none",
borderRadius: "4px",
cursor: "pointer",
}}
>
Iniciar Sesión Sin Contraseña
</button>
</div>
</div>
</div>
</main>
);
+144
View File
@@ -0,0 +1,144 @@
"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";
export default function Dashboard() {
const [tipo, setTipo] = useState("");
const [value, setValue] = useState("");
const [resultados, setResultados] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const handleSubmit = async () => {
setLoading(true);
try {
const response = await axios.get(`/api/usuarios`, {
params: {
tipo,
cuenta: value,
},
});
setResultados(response.data);
} catch (err: any) {
const message =
err.response?.data?.message ||
err.message ||
'Error al iniciar sesión';
setError(message);
console.error("Error al obtener datos:", error);
setResultados([]);
} finally {
setLoading(false);
}
};
return (
<main
className="roboto"
style={{
minHeight: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
background: "#063970",
flexDirection: "column",
padding: "2rem",
}}
>
<div
className="flex gap-4 flex-wrap mb-6"
style={{
background: "#f3f4f6",
padding: "2rem",
borderRadius: "8px",
boxShadow: "0 4px 6px rgba(253, 253, 253, 0.1)",
width: "100%",
maxWidth: "900px",
}}
>
<div
style={{
display: "flex",
flexDirection: "row",
justifyContent: "center",
gap: "16px",
flexWrap: "wrap",
width: "100%",
}}
>
<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"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
<Button onClick={handleSubmit}>
{loading ? "Consultando..." : "Enviar Formulario"}
</Button>
</div>
</div>
{error && (
<p style={{ color: "red", marginTop: "0.5rem", textAlign: "center" }}>{error}</p>
)}
{/* Resultados */}
{resultados.length > 0 && (
<table
style={{
background: "#fff",
borderCollapse: "collapse",
width: "100%",
maxWidth: "900px",
borderRadius: "8px",
overflow: "hidden",
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
}}
>
<thead style={{ backgroundColor: "#2563eb", color: "#fff" }}>
<tr>
{Object.keys(resultados[0]).map((key) => (
<th
key={key}
style={{ padding: "1rem", textAlign: "left", borderBottom: "1px solid #ccc" }}
>
{key.toUpperCase()}
</th>
))}
</tr>
</thead>
<tbody>
{resultados.map((item, idx) => (
<tr key={idx}>
{Object.values(item).map((val, i) => (
<td key={i} style={{ padding: "0.75rem", borderBottom: "1px solid #eee" }}>
{String(val)}
</td>
))}
</tr>
))}
</tbody>
</table>
)}
</main>
);
}
+6
View File
@@ -40,6 +40,12 @@ const CargaArchivo: React.FC = () => {
onClick={handleUpload}
disabled={!archivo}
className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
style={{
backgroundColor: "#2563eb",
color: "#fff",
}}
>
Subir archivo
</button>
+103
View File
@@ -0,0 +1,103 @@
import React, { useId } from 'react';
interface Option {
value: string | number;
label: string;
}
interface SelectProps
extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, 'className'> {
label: string;
className?: {
container?: string;
label?: string;
input?: string;
};
options: Option[];
placeholder?: string;
}
/**
* Componente `Select` reutilizable en React.
*
* Este componente renderiza un elemento `<select>` con una etiqueta visible,
* opciones personalizadas y estilos configurables por clase. Es compatible
* con el uso controlado (`value`) o no controlado (`defaultValue`).
*
* Además, genera automáticamente un `id` si no se proporciona, manteniendo
* buenas prácticas de accesibilidad.
*
* @component
* @example
* // Uso básico
* <Select
* label="País"
* name="pais"
* options={[
* { value: 'mx', label: 'México' },
* { value: 'us', label: 'Estados Unidos' },
* { value: 'ca', label: 'Canadá' }
* ]}
* placeholder="Selecciona un país"
* defaultValue=""
* />
*
* @param {Object} props - Propiedades del componente.
* @param {string} props.label - Etiqueta visible asociada al campo.
* @param {Array<{ value: string | number, label: string }>} props.options - Lista de opciones disponibles en el select.
* @param {string} [props.placeholder] - Opción deshabilitada inicial que actúa como guía o título (si se proporciona).
* @param {string} [props.name] - Nombre del campo (útil en formularios).
* @param {string} [props.id] - ID del campo; si no se proporciona, se genera automáticamente.
* @param {string | number} [props.defaultValue] - Valor por defecto del select (modo no controlado).
* @param {string | number} [props.value] - Valor actual del select (modo controlado).
* @param {Object} [props.className] - Objeto para aplicar clases CSS personalizadas.
* @param {string} [props.className.container] - Clases del contenedor principal.
* @param {string} [props.className.label] - Clases de la etiqueta.
* @param {string} [props.className.input] - Clases del `<select>`.
* @param {React.SelectHTMLAttributes<HTMLSelectElement>} [rest] - Cualquier otra prop válida para `<select>`.
*
* @returns {JSX.Element} Un elemento `<select>` con sus opciones y etiqueta asociada.
*/
const Select: React.FC<SelectProps> = ({
label,
className,
options,
placeholder,
id,
name,
defaultValue,
value,
...rest
}) => {
const generatedId = useId();
const selectId = id || name || generatedId;
return (
<div className={`mb-3 ${className?.container ?? ''}`}>
<label htmlFor={selectId} className={`form-label ${className?.label ?? ''}`}>
{label}
</label>
<select
id={selectId}
name={name}
className={`form-select bg-white ${className?.input ?? ''}`}
defaultValue={defaultValue ?? (value === undefined ? '' : undefined)}
value={value}
{...rest}
>
{placeholder && (
<option value="" disabled>
{placeholder}
</option>
)}
{options.map((option) => (
<option key={option.value.toString()} value={option.value}>
{option.label}
</option>
))}
</select>
</div>
);
};
export default Select;
+23
View File
@@ -0,0 +1,23 @@
"use client";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
export function useAuthRedirect() {
const router = useRouter();
const [loading, setLoading] = useState(true);
useEffect(() => {
const token = localStorage.getItem("token");
// Simula verificación (puedes hacer una llamada real)
if (!token) {
router.replace("/");
} else {
// Aquí podrías verificar validez con una API, jwt-decode, etc.
setLoading(false); // Ya está autenticado, muestra contenido
}
}, [router]);
return loading;
}