Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a “missing answer type” error by preventing auto-save from including answers for questions that are not present in the currently visible sections (and therefore not present in the derived questionTypeMap).
Changes:
- Filter
answersduring auto-save payload construction to only include answers whosequestionIdexists in the currentsections. - Avoid generating update payload entries with an undefined
questionType(root cause of the error).
Comments suppressed due to low confidence (1)
src/features/form/components/FormDetailPage.tsx:284
answersArraynow scanssectionsfor each answer (sections.some(...some...)) even thoughquestionTypeMapis already built from the samesections. You can avoid the extra nested traversal (and make the intent clearer) by filtering on the presence ofquestionTypeMap[questionId](or building a Set of valid questionIds once) instead of re-walkingsectionsper entry.
.filter(([questionId]) => sections.some(section => section.questions?.some(q => q.id === questionId)))
.filter(([questionId, value]) => value !== "" && !["UPLOAD_FILE", "OAUTH_CONNECT"].includes(questionTypeMap[questionId]))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const answersArray = Object.entries(answers) | ||
| .filter(([questionId]) => sections.some(section => section.questions?.some(q => q.id === questionId))) | ||
| .filter(([questionId, value]) => value !== "" && !["UPLOAD_FILE", "OAUTH_CONNECT"].includes(questionTypeMap[questionId])) | ||
| .map(([questionId, value]) => { |
There was a problem hiding this comment.
This new filter prevents sending answers whose questionType is missing from questionTypeMap (e.g., when a section becomes hidden). However, the submit path (handleSubmit builds answersArray separately later in this file) still constructs payloads from all answers without filtering out questionIds that aren’t in sections/questionTypeMap, so the same “missing type” error can still occur on submit. Consider extracting a shared helper to build the answers payload and reuse it in both auto-save and submit, or apply the same filtering logic in handleSubmit.
Type of changes
Purpose