2
0
Files
bot/apps/builder/components/shared/SupportBubble.tsx

49 lines
1.6 KiB
TypeScript
Raw Normal View History

import { useTypebot } from 'contexts/TypebotContext'
import { useUser } from 'contexts/UserContext'
2022-05-13 15:22:44 -07:00
import { useWorkspace } from 'contexts/WorkspaceContext'
import React, { useEffect, useState } from 'react'
import { isCloudProdInstance } from 'services/utils'
2022-05-13 15:22:44 -07:00
import { planToReadable } from 'services/workspace'
2022-02-14 11:33:38 +01:00
import { initBubble } from 'typebot-js'
import { isEmpty } from 'utils'
2022-02-14 11:33:38 +01:00
export const SupportBubble = () => {
const { typebot } = useTypebot()
const { user } = useUser()
2022-05-13 15:22:44 -07:00
const { workspace } = useWorkspace()
const [localTypebotId, setLocalTypebotId] = useState(typebot?.id)
const [localUserId, setLocalUserId] = useState(user?.id)
2022-02-14 11:33:38 +01:00
useEffect(() => {
if (
isCloudProdInstance() &&
(localTypebotId !== typebot?.id || localUserId !== user?.id)
) {
setLocalTypebotId(typebot?.id)
setLocalUserId(user?.id)
initBubble({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
}/typebot-support`,
backgroundColor: '#ffffff',
2022-03-23 09:56:39 +01:00
button: {
color: '#0042DA',
},
hiddenVariables: {
'User ID': user?.id,
'First name': user?.name?.split(' ')[0] ?? undefined,
Email: user?.email ?? undefined,
'Typebot ID': typebot?.id,
'Avatar URL': user?.image ?? undefined,
2022-05-13 15:22:44 -07:00
Plan: planToReadable(workspace?.plan),
},
})
}
2022-02-14 11:33:38 +01:00
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [user, typebot])
2022-02-14 11:33:38 +01:00
return <></>
}