2
0

🔒 Expose minimum data to NEXT_DATA json

This commit is contained in:
Baptiste Arnaud
2023-08-14 16:55:47 +02:00
parent 401efa9d0c
commit de616ea649
2 changed files with 106 additions and 64 deletions

View File

@@ -3,23 +3,28 @@ import { BackgroundType, Typebot } from '@typebot.io/schemas'
import { useRouter } from 'next/router'
import { SEO } from './Seo'
export type TypebotPageProps = {
export type TypebotV3PageProps = {
url: string
typebot: Pick<Typebot, 'settings' | 'theme' | 'name' | 'publicId'>
name: string
publicId: string | null
isHideQueryParamsEnabled: boolean | null
background: Typebot['theme']['general']['background']
metadata: Typebot['settings']['metadata']
}
export const TypebotPageV3 = ({ url, typebot }: TypebotPageProps) => {
export const TypebotPageV3 = ({
publicId,
name,
url,
isHideQueryParamsEnabled,
metadata,
background,
}: TypebotV3PageProps) => {
const { asPath, push } = useRouter()
const background = typebot?.theme.general.background
const clearQueryParamsIfNecessary = () => {
const hasQueryParams = asPath.includes('?')
if (
!hasQueryParams ||
!(typebot?.settings.general.isHideQueryParamsEnabled ?? true)
)
return
if (!hasQueryParams || !(isHideQueryParamsEnabled ?? true)) return
push(asPath.split('?')[0], undefined, { shallow: true })
}
@@ -36,15 +41,8 @@ export const TypebotPageV3 = ({ url, typebot }: TypebotPageProps) => {
: '#fff',
}}
>
<SEO
url={url}
typebotName={typebot.name}
metadata={typebot.settings.metadata}
/>
<Standard
typebot={typebot.publicId}
onInit={clearQueryParamsIfNecessary}
/>
<SEO url={url} typebotName={name} metadata={metadata} />
<Standard typebot={publicId} onInit={clearQueryParamsIfNecessary} />
</div>
)
}