feat(viewer): 💄 Clear param on page load
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { TypebotViewer } from 'bot-engine'
|
import { TypebotViewer } from 'bot-engine'
|
||||||
import { Answer, PublicTypebot, VariableWithValue } from 'models'
|
import { Answer, PublicTypebot, VariableWithValue } from 'models'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { upsertAnswer } from 'services/answer'
|
import { upsertAnswer } from 'services/answer'
|
||||||
import { SEO } from '../components/Seo'
|
import { SEO } from '../components/Seo'
|
||||||
@ -19,6 +20,7 @@ export const TypebotPage = ({
|
|||||||
isIE,
|
isIE,
|
||||||
url,
|
url,
|
||||||
}: TypebotPageProps & { typebot: PublicTypebot }) => {
|
}: TypebotPageProps & { typebot: PublicTypebot }) => {
|
||||||
|
const { asPath, push } = useRouter()
|
||||||
const [showTypebot, setShowTypebot] = useState(false)
|
const [showTypebot, setShowTypebot] = useState(false)
|
||||||
const [predefinedVariables, setPredefinedVariables] = useState<{
|
const [predefinedVariables, setPredefinedVariables] = useState<{
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
@ -30,6 +32,7 @@ export const TypebotPage = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const urlParams = new URLSearchParams(location.search)
|
const urlParams = new URLSearchParams(location.search)
|
||||||
|
clearQueryParams()
|
||||||
const predefinedVariables: { [key: string]: string } = {}
|
const predefinedVariables: { [key: string]: string } = {}
|
||||||
urlParams.forEach((value, key) => {
|
urlParams.forEach((value, key) => {
|
||||||
predefinedVariables[key] = value
|
predefinedVariables[key] = value
|
||||||
@ -39,6 +42,11 @@ export const TypebotPage = ({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// 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 initializeResult = async () => {
|
||||||
const resultIdFromSession = getExistingResultFromSession()
|
const resultIdFromSession = getExistingResultFromSession()
|
||||||
if (resultIdFromSession) setResultId(resultIdFromSession)
|
if (resultIdFromSession) setResultId(resultIdFromSession)
|
||||||
|
Reference in New Issue
Block a user