From 26f5d39baf87f969f1ee965fa7f05fccead69b22 Mon Sep 17 00:00:00 2001 From: Matthias Nannt Date: Mon, 30 Jan 2023 16:34:28 +0100 Subject: [PATCH] formbricks-com make waitlist submission synchronous again, add warmup request --- apps/formbricks-com/components/engine/Survey.tsx | 7 +++++++ apps/formbricks-com/components/engine/SurveyPage.tsx | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/formbricks-com/components/engine/Survey.tsx b/apps/formbricks-com/components/engine/Survey.tsx index a1b4bb218d..de98c29ac6 100644 --- a/apps/formbricks-com/components/engine/Survey.tsx +++ b/apps/formbricks-com/components/engine/Survey.tsx @@ -17,6 +17,13 @@ export function Survey({ survey, formbricksUrl, formId }: SurveyProps) { const schema = useMemo(() => generateSchema(survey), [survey]); + useEffect(() => { + // warmup request + fetch(`${formbricksUrl}/api/capture/forms/${formId}/submissions`, { + method: "OPTIONS", + }); + }); + const navigateToNextPage = (currentSubmission: any) => { const nextPage = calculateNextPage(survey, currentSubmission); setCurrentPage(nextPage); diff --git a/apps/formbricks-com/components/engine/SurveyPage.tsx b/apps/formbricks-com/components/engine/SurveyPage.tsx index 66f6c1834b..3c7b940e95 100644 --- a/apps/formbricks-com/components/engine/SurveyPage.tsx +++ b/apps/formbricks-com/components/engine/SurveyPage.tsx @@ -93,8 +93,7 @@ export function SurveyPage({ const updatedSubmission = { ...submission, ...data }; setSubmission(updatedSubmission); try { - sendToFormbricks(data); - await waitForAnimation(400); + await sendToFormbricks(data); setSubmittingPage(false); onSubmit(updatedSubmission); plausible(`waitlistSubmitPage-${page.id}`); @@ -104,9 +103,6 @@ export function SurveyPage({ } }; - // set timeout promise - const waitForAnimation = (ms: number) => new Promise((res) => setTimeout(res, ms)); - const handleSubmitElement = () => { if (page.config?.autoSubmit && page.elements.length == 1) { formRef.current?.requestSubmit();