Skip to content

Commit

Permalink
fix(surveys): add missing logic for the *Thank you header* field (#17647
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jurajmajerik authored Sep 27, 2023
1 parent 4f409b1 commit e7d5d3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
21 changes: 15 additions & 6 deletions frontend/src/scenes/surveys/Survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,23 @@ export function SurveyForm({ id }: { id: string }): JSX.Element {
<Field name="type" label="Question type" className="max-w-60">
<LemonSelect
onSelect={(newType) => {
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 },
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/scenes/surveys/surveyLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const defaultSurveyFieldValues = {
],
appearance: {
submitButtonText: 'Submit',
thankYouMessageHeader: 'Thank you for your feedback!',
},
},
[SurveyQuestionType.Link]: {
Expand All @@ -94,7 +95,9 @@ export const defaultSurveyFieldValues = {
upperBoundLabel: 'Very likely',
},
],
appearance: {},
appearance: {
thankYouMessageHeader: 'Thank you for your feedback!',
},
},
[SurveyQuestionType.SingleChoice]: {
questions: [
Expand All @@ -106,6 +109,7 @@ export const defaultSurveyFieldValues = {
],
appearance: {
submitButtonText: 'Submit',
thankYouMessageHeader: 'Thank you for your feedback!',
},
},
[SurveyQuestionType.MultipleChoice]: {
Expand All @@ -118,6 +122,7 @@ export const defaultSurveyFieldValues = {
],
appearance: {
submitButtonText: 'Submit',
thankYouMessageHeader: 'Thank you for your feedback!',
},
},
}
Expand Down Expand Up @@ -189,11 +194,13 @@ export const surveyLogic = kea<surveyLogicType>([
setDefaultForQuestionType: (
type: SurveyQuestionType,
isEditingQuestion: boolean,
isEditingDescription: boolean
isEditingDescription: boolean,
isEditingThankYouMessage: boolean
) => ({
type,
isEditingQuestion,
isEditingDescription,
isEditingThankYouMessage,
}),
launchSurvey: true,
stopSurvey: true,
Expand Down Expand Up @@ -268,13 +275,19 @@ export const surveyLogic = kea<surveyLogicType>([
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,
Expand All @@ -289,6 +302,7 @@ export const surveyLogic = kea<surveyLogicType>([
appearance: {
...state.appearance,
...defaultSurveyFieldValues[type].appearance,
thankYouMessageHeader,
},
}
},
Expand Down

0 comments on commit e7d5d3b

Please sign in to comment.