fixed update and create machine and added button to dowload excel
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user