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
+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>
);
}