diff --git a/cope2n-ai-fi/modules/sdsvkvu b/cope2n-ai-fi/modules/sdsvkvu index 6907ea0..b6d4fab 160000 --- a/cope2n-ai-fi/modules/sdsvkvu +++ b/cope2n-ai-fi/modules/sdsvkvu @@ -1 +1 @@ -Subproject commit 6907ea0183b141e3b4f3c21758c9123f1e9b2a27 +Subproject commit b6d4fab46f7f8689dd6b050cfbff2faa6a6f3fec diff --git a/cope2n-fe/src/components/report-detail/report-table.tsx b/cope2n-fe/src/components/report-detail/report-table.tsx index 09e7550..72a200e 100644 --- a/cope2n-fe/src/components/report-detail/report-table.tsx +++ b/cope2n-fe/src/components/report-detail/report-table.tsx @@ -19,10 +19,10 @@ const ReportTable: React.FC = () => { })); const handleDownloadReport = async (report_id: string) => { - const reportFile = await downloadReport(report_id); + const {file, filename} = await downloadReport(report_id); const anchorElement = document.createElement('a'); - anchorElement.href = URL.createObjectURL(reportFile); - anchorElement.download = `${report_id}.xlsx`; // Set the desired new filename + anchorElement.href = URL.createObjectURL(file); + anchorElement.download = filename; document.body.appendChild(anchorElement); anchorElement.click(); diff --git a/cope2n-fe/src/pages/reports/report_detail/index.tsx b/cope2n-fe/src/pages/reports/report_detail/index.tsx index 10546ad..57d4eb7 100644 --- a/cope2n-fe/src/pages/reports/report_detail/index.tsx +++ b/cope2n-fe/src/pages/reports/report_detail/index.tsx @@ -258,10 +258,10 @@ const ReportDetail = () => { }); const report_data = data as ReportDetailList; const handleDownloadReport = async () => { - const reportFile = await downloadReport(id); + const {file, filename} = await downloadReport(id); const anchorElement = document.createElement('a'); - anchorElement.href = URL.createObjectURL(reportFile); - anchorElement.download = `${id}.xlsx`; // Set the desired new filename + anchorElement.href = URL.createObjectURL(file); + anchorElement.download = filename; document.body.appendChild(anchorElement); anchorElement.click(); diff --git a/cope2n-fe/src/request/report.ts b/cope2n-fe/src/request/report.ts index d068283..2b65a48 100644 --- a/cope2n-fe/src/request/report.ts +++ b/cope2n-fe/src/request/report.ts @@ -93,12 +93,23 @@ export async function downloadReport(report_id: string) { const response = await API.get(`/ctel/get_report_file/${report_id}/`, { responseType: 'blob', // Important }); + let filename = "report.xlsx"; + try { + let basename = response.headers['content-disposition'].split('filename=')[1].split('.')[0]; + let extension = response.headers['content-disposition'].split('.')[1].split(';')[0]; + filename = `${basename}.${extension}` + } catch(err) { + console.log(err); + } const file = new Blob([response.data], { type: 'application/vnd.ms-excel', }); // const fileURL = URL.createObjectURL(file); // window.open(fileURL); - return file; + return { + file: file, + filename: filename, + } } catch (error) { notification.error({ message: `${error?.message}`,