fixed update and create machine and added button to dowload excel

This commit is contained in:
2025-11-21 08:33:42 -06:00
parent b2757dd18f
commit 9c4b474225
5 changed files with 111 additions and 19 deletions
+11 -10
View File
@@ -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<PreguntaKey, string> = {
pregunta1: "Impresoras",
@@ -30,16 +28,21 @@ export default function Page() {
<Pregunta1EP />
<Pregunta2EP />
</>
)
);
case "pregunta4":
return (
<>
<Pregunta4EP />
<Pregunta5EP />
</>
)
);
case "pregunta7":
return <Pregunta7 />;
return (
<>
<Pregunta7 />
<DownloadReporteXLSX/>
</>
);
default:
return (
<div className="p-6 text-center text-gray-500">
@@ -66,9 +69,7 @@ export default function Page() {
</button>
))}
</div>
<div className={`data-table_reporte`}>
{renderPregunta()}
</div>
<div className={`data-table_reporte`}>{renderPregunta()}</div>
</div>
</div>
</div>
+1 -3
View File
@@ -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;
}
+43
View File
@@ -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 (
<button className={styles.downloadBtn} onClick={handleDownload}>
<span className={styles.icon}></span>
Descargar XLSX
</button>
);
}
+47
View File
@@ -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;
}
+9 -6
View File
@@ -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.");