fix: do not create a display if the survey is in preview mode (#304)

This commit is contained in:
Moritz Rengert
2023-05-26 10:29:30 +02:00
committed by GitHub
parent e7a0821901
commit d0f8f8d57d

View File

@@ -30,9 +30,14 @@ export default function LinkSurvey({ survey }: LinkSurveyProps) {
const [responseId, setResponseId] = useState<string | null>(null);
const [displayId, setDisplayId] = useState<string | null>(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);