Skip to content

Commit

Permalink
Fix processing of 'other' choice in application question
Browse files Browse the repository at this point in the history
  • Loading branch information
JiashuHarryHuang committed May 15, 2024
1 parent b2d0bd8 commit a90587d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/Event/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const Event = ({ event }: { event: QueriedVolunteerEventDTO }) => {
}
};

console.log('event: ', event);
return (
<>
<EventBox>
Expand Down
23 changes: 22 additions & 1 deletion components/Event/EventApplication/ApplicationPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,34 @@ const processAnswers = (answerObj: any) => {
// we need to convert this into an array of application answers
const answers = Object.keys(answerObj).map(key => {
const answer = answerObj[key];
if (key.includes('Comment')) {
const questionId = key.replace('-Comment', '');
return {
questionId: questionId,
text: Array.isArray(answer) ? answer : [answer],
};
}
return {
questionId: key,
// check if the answer is an array, if not convert it into an array
text: Array.isArray(answer) ? answer : [answer],
};
});

return answers;
// combine answers with duplicate questionId
const combinedAnswers: any[] = [];
answers.forEach(answer => {
const existingAnswer = combinedAnswers.find(
a => a.questionId === answer.questionId
);
if (existingAnswer) {
existingAnswer.text = [...existingAnswer.text, ...answer.text];
} else {
combinedAnswers.push(answer);
}
});

return combinedAnswers;
};

// TODO modify survey model
Expand Down Expand Up @@ -101,6 +121,7 @@ export default function ApplicationPopup({
let survey = new Model(makeSurveyModel(questions));

survey.onComplete.add(async result => {
console.log('Survey results: ', result.data);
const answers = processAnswers(result.data);
console.log('Survey results: ', answers);
// send the answers to the server
Expand Down

0 comments on commit a90587d

Please sign in to comment.