From 9c4b47422532c8a0a02bc7e3e95f1089a3ea038f Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Fri, 21 Nov 2025 08:33:42 -0600 Subject: [PATCH] fixed update and create machine and added button to dowload excel --- src/app/(Administrador)/perifericos/page.tsx | 21 ++++----- src/components/AgregarEquipo.tsx | 4 +- src/components/Dowload/Reporte.tsx | 43 ++++++++++++++++++ src/components/Dowload/style.module.css | 47 ++++++++++++++++++++ src/components/Editar.tsx | 15 ++++--- 5 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 src/components/Dowload/Reporte.tsx create mode 100644 src/components/Dowload/style.module.css diff --git a/src/app/(Administrador)/perifericos/page.tsx b/src/app/(Administrador)/perifericos/page.tsx index 82a6752..f60e798 100644 --- a/src/app/(Administrador)/perifericos/page.tsx +++ b/src/app/(Administrador)/perifericos/page.tsx @@ -7,11 +7,9 @@ import Pregunta2EP from "@/components/Perifericos/Pregunta2EP"; import Pregunta4EP from "@/components/Perifericos/Pregunta4EP"; import Pregunta5EP from "@/components/Perifericos/Pregunta5EP"; import "../../styles/layout/reporte.scss"; +import DownloadReporteXLSX from "@/components/Dowload/Reporte"; -type PreguntaKey = - | "pregunta1" - | "pregunta4" - | "pregunta7"; +type PreguntaKey = "pregunta1" | "pregunta4" | "pregunta7"; const LABELS: Record = { pregunta1: "Impresoras", @@ -30,16 +28,21 @@ export default function Page() { - ) + ); case "pregunta4": return ( <> - ) + ); case "pregunta7": - return ; + return ( + <> + + + + ); default: return (
@@ -66,9 +69,7 @@ export default function Page() { ))}
-
- {renderPregunta()} -
+
{renderPregunta()}
diff --git a/src/components/AgregarEquipo.tsx b/src/components/AgregarEquipo.tsx index f08e605..8d5232e 100644 --- a/src/components/AgregarEquipo.tsx +++ b/src/components/AgregarEquipo.tsx @@ -385,10 +385,8 @@ export default function Page() { toast.success("Equipo guardado correctamente"); router.push("/escaner"); } catch (err: any) { - console.error(err); - if (err.response && err.response.status === 400) { - const mensaje = err.response.data?.message || "El equipo ya 1existe"; + const mensaje = err.response.data?.message || "El equipo ya existe"; toast.error(mensaje); return; } diff --git a/src/components/Dowload/Reporte.tsx b/src/components/Dowload/Reporte.tsx new file mode 100644 index 0000000..6b542cb --- /dev/null +++ b/src/components/Dowload/Reporte.tsx @@ -0,0 +1,43 @@ +"use client"; + +import styles from "./style.module.css"; +import Cookies from "js-cookie"; + +export default function DownloadReporteXLSX() { + const handleDownload = async () => { + const token = Cookies.get("token"); + const headers = { Authorization: `Bearer ${token}` }; + + try { + const response = await fetch( + "https://venus.acatlan.unam.mx/censo_test/equipos/reporteXLSX",{headers} + ); + + if (!response.ok) { + throw new Error("Error al descargar el archivo"); + } + + const blob = await response.blob(); + const url = window.URL.createObjectURL(blob); + + const a = document.createElement("a"); + a.href = url; + a.download = "reporte.xlsx"; + document.body.appendChild(a); + a.click(); + a.remove(); + + window.URL.revokeObjectURL(url); + } catch (error) { + console.error(error); + alert("Hubo un problema al descargar el archivo."); + } + }; + + return ( + + ); +} diff --git a/src/components/Dowload/style.module.css b/src/components/Dowload/style.module.css new file mode 100644 index 0000000..f44b599 --- /dev/null +++ b/src/components/Dowload/style.module.css @@ -0,0 +1,47 @@ +.downloadBtn { + display: flex; + align-items: center; + gap: 8px; + background: #1a73e8; + color: white; + border: none; + padding: 10px 16px; + cursor: pointer; + border-radius: 6px; + font-size: 14px; + font-weight: 600; + transition: background 0.2s ease; +} + +.downloadBtn:hover { + background: #1459b3; +} + +/* Icono con css puro */ +.icon { + width: 18px; + height: 18px; + position: relative; +} + +.icon::before { + content: ""; + width: 3px; + height: 10px; + background: white; + position: absolute; + left: 7px; + top: 0; +} + +.icon::after { + content: ""; + width: 10px; + height: 10px; + border-left: 3px solid white; + border-bottom: 3px solid white; + transform: rotate(-45deg); + position: absolute; + left: 4px; + top: 8px; +} diff --git a/src/components/Editar.tsx b/src/components/Editar.tsx index b1dbb4d..080a202 100644 --- a/src/components/Editar.tsx +++ b/src/components/Editar.tsx @@ -108,7 +108,6 @@ export default function Editar() { const api_url = process.env.NEXT_PUBLIC_API_URL; const mostrarCamposComputadora = Number(formData.id_tipo_equipo) !== 9; - // 🔹 Cargar catálogos useEffect(() => { const fetchCatalogos = async () => { const token = Cookies.get("token"); @@ -194,8 +193,12 @@ export default function Editar() { marca: { id_marca: number; marca: string }; periferico: { id_periferico: number; periferico: string }; observaciones?: string; - id_laboratorio?: number; - id_proyecto?: number; + laboratorio:{ + id_laboratorio?: number; + } + proyecto:{ + id_proyecto?: number; + } } const fetchEquipo = async () => { @@ -245,8 +248,8 @@ export default function Editar() { id_adscripcion: equipo.adscripcion?.id_adscripcion || 0, lugar: equipo.lugar || "", id_periferico: equipo.periferico?.id_periferico || 0, - id_laboratorio: equipo.id_laboratorio || 0, - id_proyecto: equipo.id_proyecto || 0, + id_laboratorio: equipo.laboratorio?.id_laboratorio || 0, + id_proyecto: equipo.proyecto?.id_proyecto || 0, fechaMovimiento: equipo.fechaMovimiento || "", responsable, }); @@ -390,7 +393,7 @@ export default function Editar() { headers, }); toast.success("Equipo actualizado correctamente"); - // router.push("/escaner"); + router.push("/escaner"); } catch (error) { console.error("Error al guardar:", error); toast.error("Hubo un error al guardar el equipo.");