Skip to content

Commit

Permalink
fix (projectDetails): download - file name renamed when user download…
Browse files Browse the repository at this point in the history
… forms or tasks
  • Loading branch information
NSUWAL123 committed Nov 6, 2023
1 parent ab8ddce commit 100fbd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/frontend/src/api/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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) {
Expand All @@ -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) => {
Expand Down
12 changes: 10 additions & 2 deletions src/frontend/src/components/ProjectDetails/ProjectOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
}
};
Expand Down

0 comments on commit 100fbd4

Please sign in to comment.