From 93811a3c48ca43da8d3befbf9e4222d105a06f61 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 19 Apr 2022 14:54:20 -0700 Subject: [PATCH] =?UTF-8?q?feat(viewer):=20=F0=9F=92=84=20Clear=20param=20?= =?UTF-8?q?on=20page=20load?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/viewer/layouts/TypebotPage.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/viewer/layouts/TypebotPage.tsx b/apps/viewer/layouts/TypebotPage.tsx index 4fe9a40cf..040f54d85 100644 --- a/apps/viewer/layouts/TypebotPage.tsx +++ b/apps/viewer/layouts/TypebotPage.tsx @@ -1,5 +1,6 @@ import { TypebotViewer } from 'bot-engine' import { Answer, PublicTypebot, VariableWithValue } from 'models' +import { useRouter } from 'next/router' import React, { useEffect, useState } from 'react' import { upsertAnswer } from 'services/answer' import { SEO } from '../components/Seo' @@ -19,6 +20,7 @@ export const TypebotPage = ({ isIE, url, }: TypebotPageProps & { typebot: PublicTypebot }) => { + const { asPath, push } = useRouter() const [showTypebot, setShowTypebot] = useState(false) const [predefinedVariables, setPredefinedVariables] = useState<{ [key: string]: string @@ -30,6 +32,7 @@ export const TypebotPage = ({ useEffect(() => { const urlParams = new URLSearchParams(location.search) + clearQueryParams() const predefinedVariables: { [key: string]: string } = {} urlParams.forEach((value, key) => { predefinedVariables[key] = value @@ -39,6 +42,11 @@ export const TypebotPage = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []) + const clearQueryParams = () => { + const hasQueryParams = asPath.includes('?') + if (hasQueryParams) push(asPath.split('?')[0], undefined, { shallow: true }) + } + const initializeResult = async () => { const resultIdFromSession = getExistingResultFromSession() if (resultIdFromSession) setResultId(resultIdFromSession)