-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9aba27
commit f4e6f63
Showing
32 changed files
with
1,115 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 9 additions & 4 deletions
13
apps/builder/components/dashboard/FolderContent/CreateBotButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import { | ||
chakra, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalOverlay, | ||
useDisclosure, | ||
useToast, | ||
} from '@chakra-ui/react' | ||
import { TypebotViewer } from 'bot-engine' | ||
import { useUser } from 'contexts/UserContext' | ||
import { Answer, Typebot } from 'models' | ||
import React, { useEffect, useRef, useState } from 'react' | ||
import { parseTypebotToPublicTypebot } from 'services/publicTypebot' | ||
import { sendRequest } from 'utils' | ||
import confetti from 'canvas-confetti' | ||
|
||
type Props = { totalTypebots: number } | ||
|
||
export const OnboardingModal = ({ totalTypebots }: Props) => { | ||
const { user, saveUser } = useUser() | ||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
const [typebot, setTypebot] = useState<Typebot>() | ||
const confettiCanvaContainer = useRef<HTMLCanvasElement | null>(null) | ||
const confettiCanon = useRef<confetti.CreateTypes>() | ||
const [chosenCategories, setChosenCategories] = useState<string[]>([]) | ||
|
||
const toast = useToast({ | ||
position: 'top-right', | ||
status: 'error', | ||
}) | ||
|
||
useEffect(() => { | ||
fetchTemplate() | ||
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []) | ||
|
||
useEffect(() => { | ||
const isNewUser = | ||
user && | ||
new Date(user?.createdAt as unknown as string).toDateString() === | ||
new Date().toDateString() && | ||
totalTypebots === 0 | ||
if (isNewUser) onOpen() | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [user]) | ||
|
||
useEffect(() => { | ||
initConfettis() | ||
return () => { | ||
window.removeEventListener('message', handleIncomingMessage) | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [confettiCanvaContainer.current]) | ||
|
||
const initConfettis = () => { | ||
if (!confettiCanvaContainer.current || confettiCanon.current) return | ||
confettiCanon.current = confetti.create(confettiCanvaContainer.current, { | ||
resize: true, | ||
useWorker: true, | ||
}) | ||
window.addEventListener('message', handleIncomingMessage) | ||
} | ||
|
||
const handleIncomingMessage = (message: MessageEvent) => { | ||
if (message.data.from === 'typebot') { | ||
if (message.data.action === 'shootConfettis' && confettiCanon.current) | ||
shootConfettis(confettiCanon.current) | ||
} | ||
} | ||
|
||
const fetchTemplate = async () => { | ||
const { data, error } = await sendRequest(`/bots/onboarding.json`) | ||
if (error) return toast({ title: error.name, description: error.message }) | ||
setTypebot(data as Typebot) | ||
} | ||
|
||
const handleNewAnswer = (answer: Answer) => { | ||
const isName = answer.variableId === 'cl126f4hf000i2e6d8zvzc3t1' | ||
const isCompany = answer.variableId === 'cl126jqww000w2e6dq9yv4ifq' | ||
const isCategories = answer.variableId === 'cl126mo3t001b2e6dvyi16bkd' | ||
const isOtherCategories = answer.variableId === 'cl126q38p001q2e6d0hj23f6b' | ||
if (isName) saveUser({ name: answer.content }) | ||
if (isCompany) saveUser({ company: answer.content }) | ||
if (isCategories) { | ||
const onboardingCategories = answer.content.split(', ') | ||
saveUser({ onboardingCategories }) | ||
setChosenCategories(onboardingCategories) | ||
} | ||
if (isOtherCategories) | ||
saveUser({ | ||
onboardingCategories: [...chosenCategories, answer.content], | ||
}) | ||
} | ||
|
||
return ( | ||
<Modal | ||
size="3xl" | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
blockScrollOnMount={false} | ||
> | ||
<chakra.canvas | ||
ref={confettiCanvaContainer} | ||
pos="fixed" | ||
top="0" | ||
left="0" | ||
w="full" | ||
h="full" | ||
zIndex={9999} | ||
pointerEvents="none" | ||
/> | ||
<ModalOverlay /> | ||
<ModalContent h="85vh"> | ||
<ModalBody> | ||
{typebot && ( | ||
<TypebotViewer | ||
typebot={parseTypebotToPublicTypebot(typebot)} | ||
predefinedVariables={{ | ||
Name: user?.name?.split(' ')[0] ?? undefined, | ||
}} | ||
onNewAnswer={handleNewAnswer} | ||
/> | ||
)} | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
const shootConfettis = (confettiCanon: confetti.CreateTypes) => { | ||
const count = 200 | ||
const defaults = { | ||
origin: { y: 0.7 }, | ||
} | ||
|
||
const fire = ( | ||
particleRatio: number, | ||
opts: { | ||
spread: number | ||
startVelocity?: number | ||
decay?: number | ||
scalar?: number | ||
} | ||
) => { | ||
confettiCanon( | ||
Object.assign({}, defaults, opts, { | ||
particleCount: Math.floor(count * particleRatio), | ||
}) | ||
) | ||
} | ||
|
||
fire(0.25, { | ||
spread: 26, | ||
startVelocity: 55, | ||
}) | ||
fire(0.2, { | ||
spread: 60, | ||
}) | ||
fire(0.35, { | ||
spread: 100, | ||
decay: 0.91, | ||
scalar: 0.8, | ||
}) | ||
fire(0.1, { | ||
spread: 120, | ||
startVelocity: 25, | ||
decay: 0.92, | ||
scalar: 1.2, | ||
}) | ||
fire(0.1, { | ||
spread: 120, | ||
startVelocity: 45, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f4e6f63
There was a problem hiding this comment.
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
app.yvon.earth
info-click.it
tvbeat.it
chat.hayuri.id
yoda.riku.ai
jesopizz.it
gollum.riku.ai
bot.jesopizz.it
fitness.riku.ai
barrettamario.it
ilmuseoaiborghi.it
zap.fundviser.in
bot.dsignagency.com
viewer.typebot.io
bot.contakit.com
demo.wemakebots.xyz
88584434.therpm.club
bot.barrettamario.it
92109660.therpm.club
bot.digitalpointer.id
criar.somaperuzzo.com
bot.outstandbrand.com
link.venturasuceder.com
michaeljackson.riku.ai
bot.pratikmandalia.com
invite.bridesquadapp.com
forms.hiabhaykulkarni.com
typebot-viewer.vercel.app
chat.thehomebuyersusa.com
bot.adventureconsulting.hu
bot.pinpointinteractive.com
liveconvert.kandalearn.com
chat.atlasoutfittersk9.com
tarian.theiofoundation.org
liveconvert2.kandalearn.com
forms.escoladeautomacao.com.br
viewer-v2-git-main-typebot-io.vercel.app
pizzeriafantasysaporiitaliani.it
viewer-v2-typebot-io.vercel.app
f4e6f63
There was a problem hiding this comment.
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:
landing-page-v2 – ./apps/landing-page
landing-page-v2-git-main-typebot-io.vercel.app
landing-page-v2-typebot-io.vercel.app
get-typebot.com
typebot.io
www.typebot.io
www.get-typebot.com
f4e6f63
There was a problem hiding this comment.
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
app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app