diff --git a/components/Event/Event.tsx b/components/Event/Event.tsx index 8a1545e..049b1ec 100644 --- a/components/Event/Event.tsx +++ b/components/Event/Event.tsx @@ -117,6 +117,7 @@ const Event = ({ event }: { event: QueriedVolunteerEventDTO }) => { } }; + console.log('event: ', event); return ( <> diff --git a/components/Event/EventApplication/ApplicationPopup.tsx b/components/Event/EventApplication/ApplicationPopup.tsx index 8de5e58..0646633 100644 --- a/components/Event/EventApplication/ApplicationPopup.tsx +++ b/components/Event/EventApplication/ApplicationPopup.tsx @@ -55,6 +55,13 @@ 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 @@ -62,7 +69,20 @@ const processAnswers = (answerObj: any) => { }; }); - 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 @@ -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