From e7d5d3b63d4de5abd3923449c2dbb35c25557b4c Mon Sep 17 00:00:00 2001 From: Juraj Majerik Date: Wed, 27 Sep 2023 16:09:53 +0200 Subject: [PATCH] fix(surveys): add missing logic for the *Thank you header* field (#17647) --- frontend/src/scenes/surveys/Survey.tsx | 21 +++++++++++++++------ frontend/src/scenes/surveys/surveyLogic.tsx | 20 +++++++++++++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/frontend/src/scenes/surveys/Survey.tsx b/frontend/src/scenes/surveys/Survey.tsx index 3349dd7e4196d..0dd3b5a4667f7 100644 --- a/frontend/src/scenes/surveys/Survey.tsx +++ b/frontend/src/scenes/surveys/Survey.tsx @@ -120,14 +120,23 @@ export function SurveyForm({ id }: { id: string }): JSX.Element { { - const stateObj = survey.questions[0] + const questionObj = survey.questions[0] const isEditingQuestion = - defaultSurveyFieldValues[stateObj.type].questions[0].question !== - stateObj.question + defaultSurveyFieldValues[questionObj.type].questions[0].question !== + questionObj.question const isEditingDescription = - defaultSurveyFieldValues[stateObj.type].questions[0].description !== - stateObj.description - setDefaultForQuestionType(newType, isEditingQuestion, isEditingDescription) + defaultSurveyFieldValues[questionObj.type].questions[0].description !== + questionObj.description + const isEditingThankYouMessage = + defaultSurveyFieldValues[questionObj.type].appearance + .thankYouMessageHeader !== survey.appearance.thankYouMessageHeader + + setDefaultForQuestionType( + newType, + isEditingQuestion, + isEditingDescription, + isEditingThankYouMessage + ) }} options={[ { label: 'Open text', value: SurveyQuestionType.Open }, diff --git a/frontend/src/scenes/surveys/surveyLogic.tsx b/frontend/src/scenes/surveys/surveyLogic.tsx index 3b8b55107870a..2d03f7a707a8f 100644 --- a/frontend/src/scenes/surveys/surveyLogic.tsx +++ b/frontend/src/scenes/surveys/surveyLogic.tsx @@ -69,6 +69,7 @@ export const defaultSurveyFieldValues = { ], appearance: { submitButtonText: 'Submit', + thankYouMessageHeader: 'Thank you for your feedback!', }, }, [SurveyQuestionType.Link]: { @@ -94,7 +95,9 @@ export const defaultSurveyFieldValues = { upperBoundLabel: 'Very likely', }, ], - appearance: {}, + appearance: { + thankYouMessageHeader: 'Thank you for your feedback!', + }, }, [SurveyQuestionType.SingleChoice]: { questions: [ @@ -106,6 +109,7 @@ export const defaultSurveyFieldValues = { ], appearance: { submitButtonText: 'Submit', + thankYouMessageHeader: 'Thank you for your feedback!', }, }, [SurveyQuestionType.MultipleChoice]: { @@ -118,6 +122,7 @@ export const defaultSurveyFieldValues = { ], appearance: { submitButtonText: 'Submit', + thankYouMessageHeader: 'Thank you for your feedback!', }, }, } @@ -189,11 +194,13 @@ export const surveyLogic = kea([ setDefaultForQuestionType: ( type: SurveyQuestionType, isEditingQuestion: boolean, - isEditingDescription: boolean + isEditingDescription: boolean, + isEditingThankYouMessage: boolean ) => ({ type, isEditingQuestion, isEditingDescription, + isEditingThankYouMessage, }), launchSurvey: true, stopSurvey: true, @@ -268,13 +275,19 @@ export const surveyLogic = kea([ survey: [ { ...NEW_SURVEY } as NewSurvey | Survey, { - setDefaultForQuestionType: (state, { type, isEditingQuestion, isEditingDescription }) => { + setDefaultForQuestionType: ( + state, + { type, isEditingQuestion, isEditingDescription, isEditingThankYouMessage } + ) => { const question = isEditingQuestion ? state.questions[0].question : defaultSurveyFieldValues[type].questions[0].question const description = isEditingDescription ? state.questions[0].description : defaultSurveyFieldValues[type].questions[0].description + const thankYouMessageHeader = isEditingThankYouMessage + ? state.appearance.thankYouMessageHeader + : defaultSurveyFieldValues[type].appearance.thankYouMessageHeader return { ...state, @@ -289,6 +302,7 @@ export const surveyLogic = kea([ appearance: { ...state.appearance, ...defaultSurveyFieldValues[type].appearance, + thankYouMessageHeader, }, } },