Skip to content

Commit

Permalink
fix(frontend): update the body of generate-project-data;parse null as…
Browse files Browse the repository at this point in the history
… a json instead of form data (#1919)
  • Loading branch information
Sujanadh authored Nov 28, 2024
1 parent 53b4c75 commit 7cbbd3c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/frontend/src/api/CreateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,34 +190,37 @@ const GenerateProjectFilesService = (url: string, projectData: any, formUpload:
let isAPISuccess = true;
try {
let response;

const additional_entities: string[] =
projectData?.additional_entities?.length > 0
? [projectData?.additional_entities?.[0]?.replaceAll(' ', '_')]
: [];

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 generateApiFormData = new FormData();
generateApiFormData.append(
'additional_entities',
additional_entities?.length > 0 ? additional_entities : null,
);
response = await axios.post(url, generateApiFormData, {
const payload = {
additional_entities: additional_entities.length > 0 ? additional_entities : null,
};
response = await axios.post(url, payload, {
headers: {
'Content-Type': 'multipart/form-data',
'Content-Type': 'application/json',
},
});
}

isAPISuccess = isStatusSuccess(response.status);
if (!isAPISuccess) {
throw new Error(`Request failed with status ${response.status}`);
Expand Down

0 comments on commit 7cbbd3c

Please sign in to comment.