From 100fbd4be2920bd1a04cdf4318d6beb075def1e0 Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Mon, 6 Nov 2023 11:15:43 +0545 Subject: [PATCH] fix (projectDetails): download - file name renamed when user download forms or tasks --- src/frontend/src/api/Project.js | 8 ++++---- .../src/components/ProjectDetails/ProjectOptions.tsx | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/api/Project.js b/src/frontend/src/api/Project.js index 6386e5df6e..302f2c17e3 100755 --- a/src/frontend/src/api/Project.js +++ b/src/frontend/src/api/Project.js @@ -63,11 +63,11 @@ export const ProjectById = (url, existingProjectList, projectId) => { }; }; -export const DownloadProjectForm = (url, payload) => { +export const DownloadProjectForm = (url, payload, projectId) => { return async (dispatch) => { dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: payload, loading: true })); - const fetchProjectForm = async (url, payload) => { + const fetchProjectForm = async (url, payload, projectId) => { try { let response; if (payload === 'form') { @@ -79,7 +79,7 @@ export const DownloadProjectForm = (url, payload) => { } const a = document.createElement('a'); a.href = window.URL.createObjectURL(response.data); - a.download = `Project_form.${payload === 'form' ? '.xls' : '.geojson'}`; + a.download = `${payload === 'form' ? `project_form_${projectId}.xls` : `task_polygons_${projectId}.geojson`}`; a.click(); dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: payload, loading: false })); } catch (error) { @@ -88,7 +88,7 @@ export const DownloadProjectForm = (url, payload) => { dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: payload, loading: false })); } }; - await fetchProjectForm(url, payload); + await fetchProjectForm(url, payload, projectId); }; }; export const DownloadDataExtract = (url, payload) => { diff --git a/src/frontend/src/components/ProjectDetails/ProjectOptions.tsx b/src/frontend/src/components/ProjectDetails/ProjectOptions.tsx index 77560b1e90..ca9be1c368 100644 --- a/src/frontend/src/components/ProjectDetails/ProjectOptions.tsx +++ b/src/frontend/src/components/ProjectDetails/ProjectOptions.tsx @@ -19,11 +19,19 @@ const ProjectOptions = ({ setToggleGenerateModal }) => { const handleDownload = (downloadType) => { if (downloadType === 'form') { dispatch( - DownloadProjectForm(`${import.meta.env.VITE_API_URL}/projects/download_form/${decodedId}/`, downloadType), + DownloadProjectForm( + `${import.meta.env.VITE_API_URL}/projects/download_form/${decodedId}/`, + downloadType, + decodedId, + ), ); } else if (downloadType === 'geojson') { dispatch( - DownloadProjectForm(`${import.meta.env.VITE_API_URL}/projects/${decodedId}/download_tasks`, downloadType), + DownloadProjectForm( + `${import.meta.env.VITE_API_URL}/projects/${decodedId}/download_tasks`, + downloadType, + decodedId, + ), ); } };