From d0f8f8d57d861a0097b5f658c5867b6d232ab5af Mon Sep 17 00:00:00 2001 From: Moritz Rengert <42251569+moritzrengert@users.noreply.github.com> Date: Fri, 26 May 2023 10:29:30 +0200 Subject: [PATCH] fix: do not create a display if the survey is in preview mode (#304) --- apps/web/app/s/[surveyId]/LinkSurvey.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/web/app/s/[surveyId]/LinkSurvey.tsx b/apps/web/app/s/[surveyId]/LinkSurvey.tsx index a265fb5c0e..68dcc519bd 100644 --- a/apps/web/app/s/[surveyId]/LinkSurvey.tsx +++ b/apps/web/app/s/[surveyId]/LinkSurvey.tsx @@ -30,9 +30,14 @@ export default function LinkSurvey({ survey }: LinkSurveyProps) { const [responseId, setResponseId] = useState(null); const [displayId, setDisplayId] = useState(null); + const isPreview = new URLSearchParams(window.location.search).get("preview") === "true"; + useEffect(() => { if (survey) { setCurrentQuestion(survey.questions[0]); + + if (isPreview) return; + // create display createDisplay( { surveyId: survey.id }, @@ -42,7 +47,7 @@ export default function LinkSurvey({ survey }: LinkSurveyProps) { setDisplayId(display.id); }); } - }, [survey]); + }, [survey, isPreview]); useEffect(() => { if (currentQuestion && survey) { @@ -55,8 +60,6 @@ export default function LinkSurvey({ survey }: LinkSurveyProps) { } }, [currentQuestion, survey]); - const isPreview = new URLSearchParams(window.location.search).get("preview") === "true"; - const restartSurvey = () => { setCurrentQuestion(survey.questions[0]); setProgress(0);