diff --git a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/summary/LinkSurveyModal.tsx b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/summary/LinkSurveyModal.tsx index 843c15b2e2..5559145dfc 100644 --- a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/summary/LinkSurveyModal.tsx +++ b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/summary/LinkSurveyModal.tsx @@ -50,7 +50,7 @@ export default function LinkSurveyModal({ survey, open, setOpen }: LinkSurveyMod variant="secondary" title="Preview survey" aria-label="Preview survey" - href={`${window.location.protocol}//${window.location.host}/s/${survey.id}`} + href={`${window.location.protocol}//${window.location.host}/s/${survey.id}?preview=true`} target="_blank" EndIcon={EyeIcon}> Preview diff --git a/apps/web/app/s/[surveyId]/LinkSurvey.tsx b/apps/web/app/s/[surveyId]/LinkSurvey.tsx index 9d8af56d52..52a68d7aa9 100644 --- a/apps/web/app/s/[surveyId]/LinkSurvey.tsx +++ b/apps/web/app/s/[surveyId]/LinkSurvey.tsx @@ -12,6 +12,7 @@ import type { Question } from "@formbricks/types/questions"; import type { Survey } from "@formbricks/types/surveys"; import { Confetti } from "@formbricks/ui"; import { useEffect, useState } from "react"; +import { ExclamationTriangleIcon, ArrowPathIcon } from "@heroicons/react/24/solid"; type EnhancedSurvey = Survey & { brandColor: string; @@ -54,6 +55,14 @@ 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); + setFinished(false); + }; + const submitResponse = async (data: { [x: string]: any }) => { setLoadingElement(true); const questionIdx = survey.questions.findIndex((e) => e.id === currentQuestion?.id); @@ -64,7 +73,7 @@ export default function LinkSurvey({ survey }: LinkSurveyProps) { surveyId: survey.id, response: { finished, data }, }; - if (!responseId) { + if (!responseId && !isPreview) { const response = await createResponse( responseRequest, `${window.location.protocol}//${window.location.host}`, @@ -78,7 +87,7 @@ export default function LinkSurvey({ survey }: LinkSurveyProps) { ); } setResponseId(response.id); - } else { + } else if (responseId && !isPreview) { await updateResponse( responseRequest, responseId, @@ -110,10 +119,21 @@ export default function LinkSurvey({ survey }: LinkSurveyProps) { <>