Skip to content

Commit

Permalink
add auto opt ins for surveys list launch and stop surveys
Browse files Browse the repository at this point in the history
  • Loading branch information
liyiy committed Oct 19, 2023
1 parent 9532df5 commit d27d909
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
24 changes: 20 additions & 4 deletions frontend/src/scenes/surveys/Surveys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function Surveys(): JSX.Element {

const { user } = useValues(userLogic)
const { currentTeam } = useValues(teamLogic)
const { updateCurrentTeam } = useActions(teamLogic)
const surveysPopupDisabled =
currentTeam && !currentTeam?.surveys_opt_in && surveys.some((s) => s.start_date && !s.end_date)

Expand Down Expand Up @@ -301,14 +302,26 @@ export function Surveys(): JSX.Element {
<LemonButton
status="stealth"
fullWidth
onClick={() =>
onClick={() => {
updateSurvey({
id: survey.id,
updatePayload: {
end_date: dayjs().toISOString(),
},
})
}
if (currentTeam && currentTeam.surveys_opt_in) {
const activeSurveys = surveys.filter(
(s) => s.start_date && !s.end_date
)
if (
activeSurveys.filter(
(s) => s.id !== survey.id
).length === 0
) {
updateCurrentTeam({ surveys_opt_in: false })
}
}
}}
>
Stop survey
</LemonButton>
Expand All @@ -317,12 +330,15 @@ export function Surveys(): JSX.Element {
<LemonButton
status="stealth"
fullWidth
onClick={() =>
onClick={() => {
if (currentTeam && !currentTeam.surveys_opt_in) {
updateCurrentTeam({ surveys_opt_in: true })
}
updateSurvey({
id: survey.id,
updatePayload: { end_date: null },
})
}
}}
>
Resume survey
</LemonButton>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/scenes/surveys/surveyLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ export const surveyLogic = kea<surveyLogicType>([
lemonToast.success(<>Survey {survey.name} created</>)
actions.loadSurveys()
router.actions.replace(urls.survey(survey.id))
if (values.currentTeam?.surveys_opt_in === false) {
actions.setSurveysOptIn(true)
}
actions.reportSurveyCreated(survey)
},
updateSurveySuccess: ({ survey }) => {
Expand All @@ -419,13 +416,16 @@ export const surveyLogic = kea<surveyLogicType>([
launchSurveySuccess: ({ survey }) => {
lemonToast.success(<>Survey {survey.name} launched</>)
actions.loadSurveys()
if (!values.currentTeam?.surveys_opt_in) {
actions.setSurveysOptIn(true)
}
actions.reportSurveyLaunched(survey)
},
stopSurveySuccess: ({ survey }) => {
actions.loadSurveys()
if (values.currentTeam?.surveys_opt_in === true) {
const hasActiveSurveys = values.surveys.some((s) => s.start_date && !s.end_date)
if (!hasActiveSurveys) {
if (values.currentTeam?.surveys_opt_in) {
const activeSurveys = values.surveys.filter((s) => s.start_date && !s.end_date)
if (activeSurveys.filter((s) => s.id !== survey.id).length === 0) {
actions.setSurveysOptIn(false)
}
}
Expand Down

0 comments on commit d27d909

Please sign in to comment.