Skip to content

Commit

Permalink
fix(surveys): fix bad survey value destructuring (#23344)
Browse files Browse the repository at this point in the history
* ooof, this is what happens when you don't sync the types

* safe lookups

* just a bit safer
  • Loading branch information
dmarticus authored Jun 28, 2024
1 parent f079205 commit 319aed7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions frontend/src/lib/utils/eventUsageLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
recurring_survey_iteration_count: survey.iteration_count == undefined ? 0 : survey.iteration_count,
recurring_survey_iteration_interval:
survey.iteration_frequency_days == undefined ? 0 : survey.iteration_frequency_days,
shuffle_questions_enabled: !!survey.appearance.shuffleQuestions,
shuffle_questions_enabled: !!survey.appearance?.shuffleQuestions,
shuffle_question_options_enabled_count: questionsWithShuffledOptions.length,
})
},
Expand Down Expand Up @@ -1267,7 +1267,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
recurring_survey_iteration_count: survey.iteration_count == undefined ? 0 : survey.iteration_count,
recurring_survey_iteration_interval:
survey.iteration_frequency_days == undefined ? 0 : survey.iteration_frequency_days,
shuffle_questions_enabled: !!survey.appearance.shuffleQuestions,
shuffle_questions_enabled: !!survey.appearance?.shuffleQuestions,
shuffle_question_options_enabled_count: questionsWithShuffledOptions.length,
})
},
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/surveys/QuestionBranchingInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function QuestionBranchingInput({
setQuestionBranchingType(questionIndex, type, specificQuestionIndex)
}

if (survey.appearance.shuffleQuestions) {
if (survey.appearance && survey.appearance.shuffleQuestions) {
LemonDialog.open({
title: 'Your survey has question shuffling enabled',
description: (
Expand Down Expand Up @@ -81,7 +81,7 @@ export function QuestionBranchingInput({
]
: []),
{
label: survey.appearance.displayThankYouMessage ? 'Confirmation message' : 'End',
label: survey.appearance?.displayThankYouMessage ? 'Confirmation message' : 'End',
value: SurveyQuestionBranchingType.End,
},
...(hasResponseBasedBranching
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/surveys/SurveyEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function SurveyEdit(): JSX.Element {
useValues(surveysLogic)
const { featureFlags } = useValues(enabledFeaturesLogic)
const sortedItemIds = survey.questions.map((_, idx) => idx.toString())
const { thankYouMessageDescriptionContentType } = survey.appearance
const { thankYouMessageDescriptionContentType = null } = survey.appearance ?? {}
const surveysRecurringScheduleDisabledReason = surveysRecurringScheduleAvailable
? undefined
: 'Subscribe to surveys for repeating surveys over a duration of time'
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/scenes/surveys/SurveyEditQuestionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function SurveyEditQuestionGroup({ index, question }: { index: number; qu
question.description
const editingThankYouMessage =
defaultSurveyFieldValues[question.type].appearance.thankYouMessageHeader !==
survey.appearance.thankYouMessageHeader
survey.appearance?.thankYouMessageHeader
setDefaultForQuestionType(
index,
newType,
Expand Down Expand Up @@ -373,7 +373,9 @@ export function SurveyEditQuestionGroup({ index, question }: { index: number; qu
<LemonField name="buttonText" label="Button text">
<LemonInput
value={
question.buttonText === undefined ? survey.appearance.submitButtonText : question.buttonText
question.buttonText === undefined
? survey.appearance?.submitButtonText ?? 'Submit'
: question.buttonText
}
/>
</LemonField>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/surveys/surveyLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export const surveyLogic = kea<surveyLogicType>([
? state.questions[idx].description
: defaultSurveyFieldValues[type].questions[0].description
const thankYouMessageHeader = isEditingThankYouMessage
? state.appearance.thankYouMessageHeader
? state.appearance?.thankYouMessageHeader
: defaultSurveyFieldValues[type].appearance.thankYouMessageHeader
const newQuestions = [...state.questions]
newQuestions[idx] = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ export interface Survey {
}[]
} | null
} | null
appearance: SurveyAppearance
appearance: SurveyAppearance | null
questions: (BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion)[]
created_at: string
created_by: UserBasicType | null
Expand Down

0 comments on commit 319aed7

Please sign in to comment.