Added initial Excel changes
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import React from "react";
|
||||
import axios from "axios";
|
||||
import { toast } from "react-toastify";
|
||||
import { BsFilePdf } from "react-icons/bs";
|
||||
import { BsFilePdf, BsFileExcel} from "react-icons/bs";
|
||||
|
||||
type DownloadingPdf = {
|
||||
[key: string]: boolean;
|
||||
};
|
||||
|
||||
type PdfEndpoint = "stats" | "assignments";
|
||||
type FileType = "pdf" | "excel";
|
||||
|
||||
export const usePDFDownload = (endpoint: PdfEndpoint) => {
|
||||
export const usePDFDownload = (endpoint: PdfEndpoint, file: FileType = 'pdf') => {
|
||||
const [downloadingPdf, setDownloadingPdf] = React.useState<DownloadingPdf>(
|
||||
{}
|
||||
);
|
||||
@@ -17,7 +18,7 @@ export const usePDFDownload = (endpoint: PdfEndpoint) => {
|
||||
const triggerDownload = async (id: string) => {
|
||||
try {
|
||||
setDownloadingPdf((prev) => ({ ...prev, [id]: true }));
|
||||
const res = await axios.post(`/api/${endpoint}/${id}/export`);
|
||||
const res = await axios.post(`/api/${endpoint}/${id}/export/${file}`);
|
||||
toast.success("Report ready!");
|
||||
const link = document.createElement("a");
|
||||
link.href = res.data;
|
||||
@@ -45,8 +46,11 @@ export const usePDFDownload = (endpoint: PdfEndpoint) => {
|
||||
<span className={`${loadingClasses} loading loading-infinity w-6`} />
|
||||
);
|
||||
}
|
||||
|
||||
const Icon = file === "excel" ? BsFileExcel : BsFilePdf;
|
||||
|
||||
return (
|
||||
<BsFilePdf
|
||||
<Icon
|
||||
className={`${downloadClasses} text-2xl cursor-pointer`}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
|
||||
Reference in New Issue
Block a user