From 598c04082207d701fb2ccd92f8ce7a429fe26d05 Mon Sep 17 00:00:00 2001 From: Sujan Adhikari Date: Fri, 29 Nov 2024 12:57:33 +0545 Subject: [PATCH] fix: edit multi additional entities names replacing space with '_' --- src/frontend/src/api/CreateProjectService.ts | 39 ++++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/frontend/src/api/CreateProjectService.ts b/src/frontend/src/api/CreateProjectService.ts index 7309cad649..da67a8a1a8 100755 --- a/src/frontend/src/api/CreateProjectService.ts +++ b/src/frontend/src/api/CreateProjectService.ts @@ -191,34 +191,41 @@ const GenerateProjectFilesService = (url: string, projectData: any, formUpload: try { let response; - const additional_entities: string[] = + const additional_entities = projectData?.additional_entities?.length > 0 - ? [projectData?.additional_entities?.[0]?.replaceAll(' ', '_')] + ? projectData.additional_entities.map((e: string) => e.replaceAll(' ', '_')) : []; + const generateApiFormData = new FormData(); + + if (additional_entities?.length > 0) { + generateApiFormData.append('additional_entities', additional_entities); + } if (projectData.form_ways === 'custom_form') { // TODO move form upload to a separate service / endpoint? - const generateApiFormData = new FormData(); generateApiFormData.append('xlsform', formUpload); - - if (additional_entities?.length > 0) { - generateApiFormData.append('additional_entities', additional_entities); - } - response = await axios.post(url, generateApiFormData, { headers: { 'Content-Type': 'multipart/form-data', }, }); } else { - const payload = { - additional_entities: additional_entities.length > 0 ? additional_entities : null, - }; - response = await axios.post(url, payload, { - headers: { - 'Content-Type': 'application/json', - }, - }); + if (additional_entities?.length > 0) { + response = await axios.post(url, generateApiFormData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); + } else { + const payload = { + additional_entities: null, + }; + response = await axios.post(url, payload, { + headers: { + 'Content-Type': 'application/json', + }, + }); + } } isAPISuccess = isStatusSuccess(response.status);