Skip to content

Commit

Permalink
fix(surveys): Show shuffle questions only if survey has multiple ques…
Browse files Browse the repository at this point in the history
…tions (#23025)

We were showing the shuffle questions checkbox option even if there was only one question in the survey.
Changed this to use a selector that checks for the number of questions in a survey to enable/disable the shuffle questions checkbox.
  • Loading branch information
Phanatic authored Jun 17, 2024
1 parent b094d50 commit ebe4e70
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion frontend/src/scenes/surveys/SurveyCustomization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LemonButton, LemonCheckbox, LemonInput, LemonSelect } from '@posthog/le
import { useValues } from 'kea'
import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'
import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'
import { surveyLogic } from 'scenes/surveys/surveyLogic'

import {
AvailableFeature,
Expand All @@ -25,6 +26,10 @@ interface WidgetCustomizationProps extends Omit<CustomizationProps, 'surveyQuest

export function Customization({ appearance, surveyQuestionItem, onAppearanceChange }: CustomizationProps): JSX.Element {
const { surveysStylingAvailable } = useValues(surveysLogic)
const { surveyShufflingQuestionsAvailable } = useValues(surveyLogic)
const surveyShufflingQuestionsDisabledReason = surveyShufflingQuestionsAvailable
? ''
: 'Please add more than one question to the survey to enable shuffling questions'
const { guardAvailableFeature } = useValues(upgradeModalLogic)
return (
<>
Expand Down Expand Up @@ -117,9 +122,9 @@ export function Customization({ appearance, surveyQuestionItem, onAppearanceChan
checked={appearance?.whiteLabel}
/>
</div>

<div className="mt-2">
<LemonCheckbox
disabledReason={surveyShufflingQuestionsDisabledReason}
label={
<div className="flex items-center">
<span>Shuffle questions</span>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/scenes/surveys/surveyLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,12 @@ export const surveyLogic = kea<surveyLogicType>([
return !!(survey.start_date && !survey.end_date)
},
],
surveyShufflingQuestionsAvailable: [
(s) => [s.survey],
(survey: Survey): boolean => {
return survey.questions.length > 1
},
],
showSurveyRepeatSchedule: [(s) => [s.schedule], (schedule: ScheduleType) => schedule == 'recurring'],
descriptionContentType: [
(s) => [s.survey],
Expand Down

0 comments on commit ebe4e70

Please sign in to comment.