Skip to content

Commit

Permalink
feat(viewer): 💄 Clear param on page load
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 19, 2022
1 parent a089a45 commit 93811a3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/viewer/layouts/TypebotPage.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

4 comments on commit 93811a3

@vercel
Copy link

@vercel vercel bot commented on 93811a3 Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 93811a3 Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 93811a3 Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.