2
0

chore: 🛂 Add context variables to support typebot

This commit is contained in:
Baptiste Arnaud
2022-02-18 17:15:18 +01:00
parent 9b9e0f6312
commit 7402ad5f6d
3 changed files with 17 additions and 3 deletions

View File

@ -1,8 +1,12 @@
import { useTypebot } from 'contexts/TypebotContext'
import { useUser } from 'contexts/UserContext'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import React, { useEffect } from 'react' import React, { useEffect } from 'react'
import { initBubble } from 'typebot-js' import { initBubble } from 'typebot-js'
export const SupportBubble = () => { export const SupportBubble = () => {
const { typebot } = useTypebot()
const { user } = useUser()
const router = useRouter() const router = useRouter()
useEffect(() => { useEffect(() => {
@ -11,6 +15,12 @@ export const SupportBubble = () => {
viewerHost: process.env.NEXT_PUBLIC_VIEWER_HOST, viewerHost: process.env.NEXT_PUBLIC_VIEWER_HOST,
backgroundColor: '#ffffff', backgroundColor: '#ffffff',
button: { color: '#0042DA' }, button: { color: '#0042DA' },
hiddenVariables: {
'Current URL': window.location.href,
'User ID': user?.id,
Email: user?.email ?? undefined,
'Typebot ID': typebot?.id,
},
}) })
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [router]) }, [router])

View File

@ -33,11 +33,14 @@ const App = ({ Component, pageProps }: AppProps) => {
{typebotId ? ( {typebotId ? (
<TypebotContext typebotId={typebotId}> <TypebotContext typebotId={typebotId}>
<Component /> <Component />
<SupportBubble />
</TypebotContext> </TypebotContext>
) : ( ) : (
<Component {...pageProps} /> <>
<Component {...pageProps} />
<SupportBubble />
</>
)} )}
<SupportBubble />
</UserContext> </UserContext>
</SessionProvider> </SessionProvider>
</KBarProvider> </KBarProvider>

View File

@ -226,7 +226,8 @@ export const checkIfPublished = (
) => ) =>
deepEqual(parseBlocksToPublicBlocks(typebot.blocks), publicTypebot.blocks) && deepEqual(parseBlocksToPublicBlocks(typebot.blocks), publicTypebot.blocks) &&
deepEqual(typebot.settings, publicTypebot.settings) && deepEqual(typebot.settings, publicTypebot.settings) &&
deepEqual(typebot.theme, publicTypebot.theme) deepEqual(typebot.theme, publicTypebot.theme) &&
deepEqual(typebot.variables, publicTypebot.variables)
export const parseDefaultPublicId = (name: string, id: string) => export const parseDefaultPublicId = (name: string, id: string) =>
toKebabCase(name) + `-${id?.slice(-7)}` toKebabCase(name) + `-${id?.slice(-7)}`