diff --git a/frontend/__snapshots__/scenes-app-surveys--new-survey.png b/frontend/__snapshots__/scenes-app-surveys--new-survey.png index 763499545f6fd..68502e4422b8a 100644 Binary files a/frontend/__snapshots__/scenes-app-surveys--new-survey.png and b/frontend/__snapshots__/scenes-app-surveys--new-survey.png differ diff --git a/frontend/src/scenes/surveys/Survey.tsx b/frontend/src/scenes/surveys/Survey.tsx index 73879b41e70ac..3349dd7e4196d 100644 --- a/frontend/src/scenes/surveys/Survey.tsx +++ b/frontend/src/scenes/surveys/Survey.tsx @@ -1,5 +1,5 @@ import { SceneExport } from 'scenes/sceneTypes' -import { NewSurvey, defaultSurveyAppearance, surveyLogic } from './surveyLogic' +import { NewSurvey, defaultSurveyAppearance, defaultSurveyFieldValues, surveyLogic } from './surveyLogic' import { BindLogic, useActions, useValues } from 'kea' import { Form, Group } from 'kea-forms' import { PageHeader } from 'lib/components/PageHeader' @@ -60,7 +60,7 @@ export function SurveyComponent({ id }: { id?: string } = {}): JSX.Element { export function SurveyForm({ id }: { id: string }): JSX.Element { const { survey, surveyLoading, isEditingSurvey, hasTargetingFlag } = useValues(surveyLogic) - const { loadSurvey, editingSurvey, setSurveyValue } = useActions(surveyLogic) + const { loadSurvey, editingSurvey, setSurveyValue, setDefaultForQuestionType } = useActions(surveyLogic) const { featureFlags } = useValues(enabledFeaturesLogic) return ( @@ -119,6 +119,16 @@ export function SurveyForm({ id }: { id: string }): JSX.Element { { + const stateObj = survey.questions[0] + const isEditingQuestion = + defaultSurveyFieldValues[stateObj.type].questions[0].question !== + stateObj.question + const isEditingDescription = + defaultSurveyFieldValues[stateObj.type].questions[0].description !== + stateObj.description + setDefaultForQuestionType(newType, isEditingQuestion, isEditingDescription) + }} options={[ { label: 'Open text', value: SurveyQuestionType.Open }, { label: 'Link', value: SurveyQuestionType.Link }, diff --git a/frontend/src/scenes/surveys/SurveyAppearance.tsx b/frontend/src/scenes/surveys/SurveyAppearance.tsx index 004b3590432e7..d46e8e02daaee 100644 --- a/frontend/src/scenes/surveys/SurveyAppearance.tsx +++ b/frontend/src/scenes/surveys/SurveyAppearance.tsx @@ -132,7 +132,12 @@ export function SurveyAppearance({ )} )} - {(type === SurveyQuestionType.Open || type === SurveyQuestionType.Link) && ( + {[ + SurveyQuestionType.Open, + SurveyQuestionType.Link, + SurveyQuestionType.SingleChoice, + SurveyQuestionType.MultipleChoice, + ].includes(type) && ( <>
Button color
([ })), actions({ editingSurvey: (editing: boolean) => ({ editing }), + setDefaultForQuestionType: ( + type: SurveyQuestionType, + isEditingQuestion: boolean, + isEditingDescription: boolean + ) => ({ + type, + isEditingQuestion, + isEditingDescription, + }), launchSurvey: true, stopSurvey: true, archiveSurvey: true, @@ -178,6 +258,35 @@ export const surveyLogic = kea([ editingSurvey: (_, { editing }) => editing, }, ], + survey: [ + { ...NEW_SURVEY } as NewSurvey | Survey, + { + setDefaultForQuestionType: (state, { type, isEditingQuestion, isEditingDescription }) => { + const question = isEditingQuestion + ? state.questions[0].question + : defaultSurveyFieldValues[type].questions[0].question + const description = isEditingDescription + ? state.questions[0].description + : defaultSurveyFieldValues[type].questions[0].description + + return { + ...state, + questions: [ + { + ...state.questions[0], + ...(defaultSurveyFieldValues[type].questions[0] as SurveyQuestionBase), + question, + description, + }, + ], + appearance: { + ...state.appearance, + ...defaultSurveyFieldValues[type].appearance, + }, + } + }, + }, + ], }), selectors({ isSurveyRunning: [ diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 32e0e2862ca3f..0d529adc829cd 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -2107,7 +2107,7 @@ export interface SurveyAppearance { thankYouMessageDescription?: string } -interface SurveyQuestionBase { +export interface SurveyQuestionBase { question: string description?: string | null required?: boolean diff --git a/playwright/e2e-vrt/layout/Navigation.spec.ts-snapshots/Navigation-App-Page-With-Side-Bar-Shown-Mobile-1-chromium-linux.png b/playwright/e2e-vrt/layout/Navigation.spec.ts-snapshots/Navigation-App-Page-With-Side-Bar-Shown-Mobile-1-chromium-linux.png index 24af8b2279910..21118658c0aa9 100644 Binary files a/playwright/e2e-vrt/layout/Navigation.spec.ts-snapshots/Navigation-App-Page-With-Side-Bar-Shown-Mobile-1-chromium-linux.png and b/playwright/e2e-vrt/layout/Navigation.spec.ts-snapshots/Navigation-App-Page-With-Side-Bar-Shown-Mobile-1-chromium-linux.png differ