Skip to content

Commit

Permalink
♿ Add an update notification popup
Browse files Browse the repository at this point in the history
Appears when a new version of Typebot is available

Closes #312
  • Loading branch information
baptisteArno committed Feb 15, 2023
1 parent 435edd0 commit 8ac3784
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/builder/src/components/MotionStack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { forwardRef, Stack, StackProps } from '@chakra-ui/react'
import { motion, MotionProps, isValidMotionProp } from 'framer-motion'

export const MotionStack = motion(
forwardRef<MotionProps & StackProps, 'div'>((props, ref) => {
const chakraProps = Object.fromEntries(
Object.entries(props).filter(([key]) => !isValidMotionProp(key))
)

return <Stack ref={ref} {...chakraProps} />
})
)
80 changes: 80 additions & 0 deletions apps/builder/src/components/NewVersionPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useTypebot } from '@/features/editor'
import { HStack, Stack, Text } from '@chakra-ui/react'
import { useEffect, useState } from 'react'
import { sendRequest } from 'utils'
import { PackageIcon } from './icons'
import { MotionStack } from './MotionStack'

const intervalDuration = 1000 * 30 // 30 seconds

export const NewVersionPopup = () => {
const { save } = useTypebot()
const [currentVersion, setCurrentVersion] = useState<string>()
const [isNewVersionAvailable, setIsNewVersionAvailable] = useState(false)
const [isReloading, setIsReloading] = useState(false)

useEffect(() => {
if (isNewVersionAvailable) return
let cancelRequest = false
const interval = setInterval(async () => {
const { data } = await sendRequest<{
commitSha: string | undefined
}>('/api/version')
if (!data || cancelRequest) return
if (!currentVersion) {
setCurrentVersion(data.commitSha)
return
}
if (currentVersion !== data.commitSha) {
setIsNewVersionAvailable(true)
}
}, intervalDuration)

return () => {
cancelRequest = true
clearInterval(interval)
}
}, [currentVersion, isNewVersionAvailable])

const saveAndReload = async () => {
if (isReloading) return
setIsReloading(true)
if (save) await save()
window.location.reload()
}

if (!isNewVersionAvailable) return null

return (
<MotionStack
pos="fixed"
bottom="20px"
left="20px"
bgColor="blue.400"
color="white"
cursor="pointer"
p="4"
px="4"
rounded="xl"
shadow="lg"
onClick={saveAndReload}
zIndex={10}
initial={{ opacity: 0, scale: 0.5 }}
animate={{ opacity: 1, scale: 1 }}
whileHover={{ scale: 1.02 }}
whileTap={{ scale: 0.98 }}
borderWidth="2px"
borderColor="blue.300"
>
<HStack spacing={3}>
<PackageIcon boxSize="32px" />
<Stack spacing={0}>
<Text fontWeight="bold">Typebot is ready to update!</Text>
<Text fontSize="sm" color="gray.200">
Click to restart
</Text>
</Stack>
</HStack>
</MotionStack>
)
}
9 changes: 9 additions & 0 deletions apps/builder/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,12 @@ export const ListIcon = (props: IconProps) => (
<line x1="3" y1="18" x2="3.01" y2="18"></line>
</Icon>
)

export const PackageIcon = (props: IconProps) => (
<Icon viewBox="0 0 24 24" {...featherIconsBaseProps} {...props}>
<line x1="16.5" y1="9.4" x2="7.5" y2="4.21"></line>
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path>
<polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline>
<line x1="12" y1="22.08" x2="12" y2="12"></line>
</Icon>
)
3 changes: 3 additions & 0 deletions apps/builder/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { toTitleCase } from 'utils'
import { Session } from 'next-auth'
import { Plan } from 'db'
import { trpc } from '@/lib/trpc'
import { NewVersionPopup } from '@/components/NewVersionPopup'

const { ToastContainer, toast } = createStandaloneToast(customTheme)

Expand Down Expand Up @@ -59,12 +60,14 @@ const App = ({
<WorkspaceProvider typebotId={typebotId}>
<Component />
<SupportBubble />
<NewVersionPopup />
</WorkspaceProvider>
</TypebotProvider>
) : (
<WorkspaceProvider>
<Component {...pageProps} />
<SupportBubble />
<NewVersionPopup />
</WorkspaceProvider>
)}
</UserProvider>
Expand Down
7 changes: 7 additions & 0 deletions apps/builder/src/pages/api/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next'

const handler = async (_req: NextApiRequest, res: NextApiResponse) => {
return res.send({ commitSha: process.env.VERCEL_GIT_COMMIT_SHA })
}

export default handler

4 comments on commit 8ac3784

@vercel
Copy link

@vercel vercel bot commented on 8ac3784 Feb 15, 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 8ac3784 Feb 15, 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-git-main-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 8ac3784 Feb 15, 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

app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 8ac3784 Feb 15, 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

ns8.vn
1stop.au
yobot.me
klujo.com
247987.com
8jours.top
aginap.com
bee.cr8.ai
bot.aws.bj
bot.bbc.bj
cat.cr8.ai
finplex.be
stan.vselise.com
start.taxtree.io
typebot.aloe.bot
voicehelp.cr8.ai
zap.fundviser.in
app.chatforms.net
bot.hostnation.de
bot.maitempah.com
bot.phuonghub.com
bot.reviewzer.com
bot.rihabilita.it
cares.urlabout.me
chat.gaswadern.de
fmm.wpwakanda.com
gentleman-shop.fr
k1.kandabrand.com
lb.ticketfute.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
support.triplo.ai
viewer.typebot.io
1988.bouclidom.com
andreimayer.com.br
bot.danyservice.it
bot.iconicbrows.it
bot.megafox.com.br
bot.neferlopez.com
bots.robomotion.io
cadu.uninta.edu.br
dicanatural.online
digitalhelp.com.au
goalsettingbot.com
pant.maxbot.com.br
positivobra.com.br
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
bot.boston-voip.com
bot.cabinpromos.com
bot.digitalbled.com
bot.dsignagency.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.ltmidias.com.br
bot.viralsangat.com
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
piazzatorre.barrettamario.it
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-git-main-typebot-io.vercel.app

Please sign in to comment.