new tabla and new dowload

This commit is contained in:
2026-03-18 18:38:01 -05:00
parent c1a9e5d195
commit 6c7be89a01
12 changed files with 353 additions and 62 deletions
+4 -4
View File
@@ -8,7 +8,7 @@ export default function DownloadReporteXLSX() {
const [loading, setLoading] = useState(false);
const handleDownload = async () => {
setLoading(true); // 🔹 Activa loader
setLoading(true);
const token = Cookies.get("token");
const headers = { Authorization: `Bearer ${token}` };
@@ -37,7 +37,7 @@ export default function DownloadReporteXLSX() {
console.error(error);
alert("Hubo un problema al descargar el archivo.");
} finally {
setLoading(false); // 🔹 Reactiva botón y oculta loader
setLoading(false);
}
};
@@ -45,10 +45,10 @@ export default function DownloadReporteXLSX() {
<button
className={styles.downloadBtn}
onClick={handleDownload}
disabled={loading} // 🔹 Botón deshabilitado
disabled={loading}
>
{loading ? (
<div className={styles.loader}></div> // 🔹 Icono de cargando
<div className={styles.loader}></div>
) : (
<img src="/excel.svg" alt="Excel" className={styles.iconExcel} width={30} height={30}/>
)}
+74
View File
@@ -0,0 +1,74 @@
"use client";
import styles from "./style.module.css";
import Cookies from "js-cookie";
import { useState } from "react";
import axios from "axios";
interface Props {
filtros: any;
count?: boolean;
}
export default function DownloadTable({ filtros,count }: Props) {
const [loading, setLoading] = useState(false);
const handleDownload = async () => {
setLoading(true);
const token = Cookies.get("token");
try {
const endpoint = count
? "/equipos/excel/tabla/count"
: "/equipos/excel/tabla";
const response = await axios.post(
`${process.env.NEXT_PUBLIC_API_URL}${endpoint}`,
filtros,
{
headers: {
Authorization: `Bearer ${token}`,
},
responseType: "blob",
}
);
const url = window.URL.createObjectURL(new Blob([response.data]));
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.");
} finally {
setLoading(false);
}
};
return (
<button
className={styles.downloadBtn}
onClick={handleDownload}
disabled={loading}
>
{loading ? (
<div className={styles.loader}></div>
) : (
<img
src="/excel.svg"
alt="Excel"
className={styles.iconExcel}
width={30}
height={30}
/>
)}
</button>
);
}
+57
View File
@@ -0,0 +1,57 @@
"use client";
import styles from "./style.module.css";
import Cookies from "js-cookie";
import { useState } from "react";
export default function DownloadTableCount() {
const [loading, setLoading] = useState(false);
const handleDownload = async () => {
setLoading(true);
const token = Cookies.get("token");
const headers = { Authorization: `Bearer ${token}` };
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/equipos/excel/tabla/count`,
{ 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.");
} finally {
setLoading(false);
}
};
return (
<button
className={styles.downloadBtn}
onClick={handleDownload}
disabled={loading}
>
{loading ? (
<div className={styles.loader}></div>
) : (
<img src="/excel.svg" alt="Excel" className={styles.iconExcel} width={30} height={30}/>
)}
</button>
);
}