added new polarGrafic

This commit is contained in:
2026-03-26 09:51:36 -05:00
parent 1de6761d03
commit dc75a7b1a7
10 changed files with 168 additions and 100 deletions
+9 -11
View File
@@ -10,33 +10,31 @@ interface Props {
count?: boolean;
}
export default function DownloadTable({ filtros,count }: Props) {
export default function DownloadTable({ filtros, count }: Props) {
const [loading, setLoading] = useState(false);
const handleDownload = async () => {
if(!filtros.length){return}
if (!filtros) { return }
setLoading(true);
const token = Cookies.get("token");
try {
const endpoint = count
? "/equipos/excel/tabla/count"
: "/equipos/excel/tabla";
const token = Cookies.get("token");
const headers = { Authorization: `Bearer ${token}` };
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}`,
},
headers,
responseType: "blob",
}
);
const url = window.URL.createObjectURL(new Blob([response.data]));
console.log(url)
const a = document.createElement("a");
a.href = url;
a.download = "reporte.xlsx";
-57
View File
@@ -1,57 +0,0 @@
"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>
);
}