Skip to content

Commit

Permalink
🚸 Update onboarding bot
Browse files Browse the repository at this point in the history
Closes #400
  • Loading branch information
baptisteArno committed Jul 25, 2023
1 parent b17177f commit 283c55c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 50 deletions.
38 changes: 9 additions & 29 deletions apps/builder/src/features/dashboard/components/OnboardingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
import { chakra, useColorModeValue } from '@chakra-ui/react'
import { Popup } from '@typebot.io/nextjs'
import { useUser } from '@/features/account/hooks/useUser'
import { Typebot } from '@typebot.io/schemas'
import React, { useEffect, useRef, useState } from 'react'
import { sendRequest } from '@typebot.io/lib'
import confetti from 'canvas-confetti'
import { useToast } from '@/hooks/useToast'
import { useRouter } from 'next/router'

type Props = { totalTypebots: number }

export const OnboardingModal = ({ totalTypebots }: Props) => {
const { push } = useRouter()
const botPath = useColorModeValue(
'/bots/onboarding.json',
'/bots/onboarding-dark.json'
)
const backgroundColor = useColorModeValue('white', '#171923')
const { user, updateUser } = useUser()
const [typebot, setTypebot] = useState<Typebot>()
const confettiCanvaContainer = useRef<HTMLCanvasElement | null>(null)
const confettiCanon = useRef<confetti.CreateTypes>()
const [chosenCategories, setChosenCategories] = useState<string[]>([])

const { showToast } = useToast()

const isNewUser =
user &&
new Date(user?.createdAt as unknown as string).toDateString() ===
new Date().toDateString() &&
totalTypebots === 0

useEffect(() => {
const fetchTemplate = async () => {
const { data, error } = await sendRequest(botPath)
if (error)
return showToast({ title: error.name, description: error.message })
setTypebot(data as Typebot)
}

fetchTemplate()
}, [botPath, showToast])

useEffect(() => {
initConfettis()
}, [])
Expand All @@ -68,12 +47,11 @@ export const OnboardingModal = ({ totalTypebots }: Props) => {
const isCompany = answer.blockId === 'cl126jioz000v2e6dwrk1f2cb'
const isCategories = answer.blockId === 'cl126lb8v00142e6duv5qe08l'
const isOtherCategories = answer.blockId === 'cl126pv7n001o2e6dajltc4qz'
const answeredAllQuestions =
isOtherCategories || (isCategories && !answer.message.includes('Other'))
if (answeredAllQuestions && confettiCanon.current)
shootConfettis(confettiCanon.current)
if (isName) updateUser({ name: answer.message })
if (isCompany) updateUser({ company: answer.message })
if (isCompany) {
updateUser({ company: answer.message })
if (confettiCanon.current) shootConfettis(confettiCanon.current)
}
if (isCategories) {
const onboardingCategories = answer.message.split(', ')
updateUser({ onboardingCategories })
Expand All @@ -97,14 +75,16 @@ export const OnboardingModal = ({ totalTypebots }: Props) => {
zIndex={9999}
pointerEvents="none"
/>
{typebot && (
{user?.email && (
<Popup
typebot={typebot}
typebot="onboarding-typebot"
prefilledVariables={{
Name: user?.name?.split(' ')[0] ?? undefined,
Name: user.name?.split(' ')[0] ?? undefined,
Email: user.email ?? undefined,
}}
theme={{
backgroundColor,
zIndex: 100,
}}
defaultOpen={isNewUser}
onAnswer={handleNewAnswer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { TypebotCardOverlay } from './TypebotButtonOverlay'
import { useI18n } from '@/locales'
import { useTypebots } from '@/features/dashboard/hooks/useTypebots'
import { TypebotInDashboard } from '@/features/dashboard/types'
import { isCloudProdInstance } from '@/helpers/isCloudProdInstance'

type Props = { folder: DashboardFolder | null }

Expand Down Expand Up @@ -160,7 +161,9 @@ export const FolderContent = ({ folder }: Props) => {

return (
<Flex w="full" flex="1" justify="center">
{typebots && <OnboardingModal totalTypebots={typebots.length} />}
{typebots && isCloudProdInstance && (
<OnboardingModal totalTypebots={typebots.length} />
)}
<Stack w="1000px" spacing={6}>
<Skeleton isLoaded={folder?.name !== undefined}>
<Heading as="h1">{folder?.name}</Heading>
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.1.7",
"version": "0.1.8",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/src/features/popup/components/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const Popup = (props: PopupProps) => {
role="dialog"
aria-modal="true"
style={{
'z-index': 42424242,
'z-index': props.theme?.zIndex ?? 42424242,
}}
>
<style>{styles}</style>
Expand Down
1 change: 1 addition & 0 deletions packages/embeds/js/src/features/popup/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export type PopupParams = {
theme?: {
width?: string
backgroundColor?: string
zIndex?: number
}
}
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.1.7",
"version": "0.1.8",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.1.7",
"version": "0.1.8",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
21 changes: 14 additions & 7 deletions packages/embeds/react/src/Bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ declare global {
type BubbleElement = HTMLElement & Props

export const Bubble = (props: Props) => {
const ref = useRef<BubbleElement | null>(null)
const bubbleElement = useRef<BubbleElement | null>(null)

const attachBubbleToDom = useCallback((props: Props) => {
const bubbleElement = document.createElement(
const newBubbleElement = document.createElement(
'typebot-bubble'
) as BubbleElement
ref.current = bubbleElement
injectPropsToElement(ref.current, props)
document.body.append(ref.current)
bubbleElement.current = newBubbleElement
injectPropsToElement(bubbleElement.current, props)
document.body.append(bubbleElement.current)
}, [])

useEffect(() => {
if (!ref.current) attachBubbleToDom(props)
injectPropsToElement(ref.current as BubbleElement, props)
if (!bubbleElement.current) attachBubbleToDom(props)
injectPropsToElement(bubbleElement.current as BubbleElement, props)
}, [attachBubbleToDom, props])

useEffect(() => {
return () => {
bubbleElement.current?.remove()
bubbleElement.current = null
}
}, [])

const injectPropsToElement = (element: BubbleElement, props: Props) => {
Object.assign(element, props)
}
Expand Down
32 changes: 23 additions & 9 deletions packages/embeds/react/src/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,39 @@ declare global {
type PopupElement = HTMLElement & Props

export const Popup = (props: Props) => {
const ref = useRef<PopupElement | null>(null)
const containerRef = useRef<HTMLDivElement | null>(null)
const popupRef = useRef<PopupElement | null>(null)

const attachPopupToDom = useCallback((props: Props) => {
const attachPopupToContainer = useCallback((props: Props) => {
const popupElement = document.createElement('typebot-popup') as PopupElement
ref.current = popupElement
injectPropsToElement(ref.current, props)
document.body.append(ref.current)
popupRef.current = popupElement
injectPropsToElement(popupRef.current, props)
if (!containerRef.current) {
console.warn(
'Could not attach popup to container because containerRef.current is null'
)
return
}
containerRef.current?.append(popupRef.current)
}, [])

useEffect(() => {
if (!ref.current) attachPopupToDom(props)
injectPropsToElement(ref.current as PopupElement, props)
}, [attachPopupToDom, props])
if (!popupRef.current) attachPopupToContainer(props)
injectPropsToElement(popupRef.current as PopupElement, props)
}, [attachPopupToContainer, props])

useEffect(() => {
return () => {
popupRef.current?.remove()
popupRef.current = null
}
}, [])

const injectPropsToElement = (element: PopupElement, props: Props) => {
Object.assign(element, props)
}

return null
return <div ref={containerRef} />
}

export default Popup

4 comments on commit 283c55c

@vercel
Copy link

@vercel vercel bot commented on 283c55c Jul 25, 2023

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
app.typebot.io
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 283c55c Jul 25, 2023

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 283c55c Jul 25, 2023

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:

viewer-v2 – ./apps/viewer

bot.robertohairlab.it
bot.sharemyreview.net
bot.synapsegameia.com
bot.truongnguyen.live
bots.baptistearno.com
botz.cloudsiteapp.com
cdd.searchcube.com.sg
chat.missarkansas.org
chatbot.ownacademy.co
chats.maisefetivo.com
claudio-barros.online
criar.somaperuzzo.com
gotasafrodisiacas.com
homerun.wpwakanda.com
mdb.assessoria.ademir
portaldasanalises.com
prenota.aldoemaria.it
revistasaudeemdia.com
sbutton.wpwakanda.com
talk.convobuilder.com
test.leadbooster.help
whats.laracardoso.com
www.hemertonsilva.com
zillabot.saaszilla.co
815639944.21000000.one
83720273.bouclidom.com
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bolsamaisbrasil.app.br
bot.chat-debora.online
bot.clubedotrader.club
bot.ilmuseoaiborghi.it
bot.louismarcondes.com
bot.perfaceacademy.com
bot.pratikmandalia.com
bot.sucessodigital.xyz
bot.t20worldcup.com.au
bot.whatsappweb.adm.br
bot2.mycompany.reviews
bot3.mycompany.reviews
bot4.mycompany.reviews
c23111azqw.nigerias.io
chat.footballmeetup.ie
conto.barrettamario.it
dieta.barrettamario.it
felipewelington.com.br
form.bridesquadapp.com
form.searchcube.com.sg
gcase.barrettamario.it
go.orodrigoribeiro.com
help.giversforgood.com
ap-main.algorithmpress.com
bcorporate.carlosbusch.com
bot.adventureconsulting.hu
bot.aestrategianova.online
bot.desafiode15dias.online
bot.descobrindotraicao.top
bot2.fusionstarreviews.com
casestudyemb.wpwakanda.com
chat.atlasoutfittersk9.com
configurator.bouclidom.com
demo.virtuesocialmedia.com
descobrincomeufilho.com.br
descobrindomeufilho.com.br
gabinete.baleia.formulario
help.atlasoutfittersk9.com
herbalife.barrettamario.it
homepageonly.wpwakanda.com
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
newsletter.itshcormeos.com
prenotazione.aldoemaria.it
protocolosecabarriga.store
robertosanchesoficial.site
rsvp.virtuesocialmedia.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
baleia.eventos.progenbr.com
bot.desafioserrabarriga.fit
bot.educacaopelodigital.com
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chat.semanalimpanome.com.br
designguide.techyscouts.com
drayuminakamuraoficial.site
liveconvert2.kandalearn.com
poll.mosaicohairboutique.it
presente.empresarias.com.mx
register.algorithmpress.com
sell.sellthemotorhome.co.uk
teste.captacao.progenbr.com
alavancagem.horadelucrar.com
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br

@vercel
Copy link

@vercel vercel bot commented on 283c55c Jul 25, 2023

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:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

Please sign in to comment.