2
0

💄 Improve new version popup animation

This commit is contained in:
Baptiste Arnaud
2023-02-22 16:59:04 +01:00
parent 00b6acca8e
commit 31711dc24d
4 changed files with 61 additions and 54 deletions

View File

@ -1,5 +1,13 @@
import { useTypebot } from '@/features/editor' import { useTypebot } from '@/features/editor'
import { Button, Flex, HStack, Stack, Text } from '@chakra-ui/react' import {
Button,
DarkMode,
Flex,
HStack,
SlideFade,
Stack,
Text,
} from '@chakra-ui/react'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { sendRequest } from 'utils' import { sendRequest } from 'utils'
import { PackageIcon } from './icons' import { PackageIcon } from './icons'
@ -42,34 +50,40 @@ export const NewVersionPopup = () => {
window.location.reload() window.location.reload()
} }
if (!isNewVersionAvailable) return null
return ( return (
<DarkMode>
<SlideFade
in={isNewVersionAvailable}
offsetY="20px"
style={{
position: 'fixed',
bottom: '18px',
left: '18px',
zIndex: 42,
}}
unmountOnExit
>
<Stack <Stack
pos="fixed"
bottom="18px"
left="18px"
bgColor="blue.400" bgColor="blue.400"
p="4" p="4"
px="4" px="4"
rounded="lg" rounded="lg"
shadow="lg" shadow="lg"
zIndex={10}
borderWidth="1px" borderWidth="1px"
borderColor="blue.300" borderColor="blue.300"
maxW="320px" maxW="320px"
> >
<HStack spacing={3}> <HStack spacing={3}>
<Stack spacing={4}> <Stack spacing={4} color="white">
<Stack spacing={1} color="white"> <Stack spacing={1}>
<HStack> <HStack>
<PackageIcon />{' '} <PackageIcon />{' '}
<Text fontWeight="bold">New version available!</Text> <Text fontWeight="bold">New version available!</Text>
</HStack> </HStack>
<Text fontSize="sm" color="gray.100"> <Text fontSize="sm" color="gray.100">
An improved version of Typebot is available. Please reload now to An improved version of Typebot is available. Please reload now
upgrade. to upgrade.
</Text> </Text>
</Stack> </Stack>
<Flex justifyContent="flex-end"> <Flex justifyContent="flex-end">
@ -80,5 +94,7 @@ export const NewVersionPopup = () => {
</Stack> </Stack>
</HStack> </HStack>
</Stack> </Stack>
</SlideFade>
</DarkMode>
) )
} }

View File

@ -102,7 +102,7 @@ export const TypebotProvider = ({
typebotId, typebotId,
}: { }: {
children: ReactNode children: ReactNode
typebotId: string typebotId?: string
}) => { }) => {
const { status } = useSession() const { status } = useSession()
const { push } = useRouter() const { push } = useRouter()

View File

@ -7,7 +7,7 @@ export const useTypebotQuery = ({
typebotId, typebotId,
onError, onError,
}: { }: {
typebotId: string typebotId?: string
onError?: (error: Error) => void onError?: (error: Error) => void
}) => { }) => {
const { data, error, mutate } = useSWR< const { data, error, mutate } = useSWR<
@ -18,7 +18,7 @@ export const useTypebotQuery = ({
isReadOnly?: boolean isReadOnly?: boolean
}, },
Error Error
>(`/api/typebots/${typebotId}`, fetcher, { >(typebotId ? `/api/typebots/${typebotId}` : null, fetcher, {
dedupingInterval: env('E2E_TEST') === 'true' ? 0 : undefined, dedupingInterval: env('E2E_TEST') === 'true' ? 0 : undefined,
}) })
if (error && onError) onError(error) if (error && onError) onError(error)

View File

@ -26,7 +26,7 @@ const App = ({
pageProps: { session, ...pageProps }, pageProps: { session, ...pageProps },
}: AppProps<{ session?: Session }>) => { }: AppProps<{ session?: Session }>) => {
useRouterProgressBar() useRouterProgressBar()
const { query, pathname, isReady } = useRouter() const { query, pathname } = useRouter()
useEffect(() => { useEffect(() => {
pathname.endsWith('/edit') pathname.endsWith('/edit')
@ -38,13 +38,12 @@ const App = ({
const newPlan = query.stripe?.toString() const newPlan = query.stripe?.toString()
if (newPlan === Plan.STARTER || newPlan === Plan.PRO) if (newPlan === Plan.STARTER || newPlan === Plan.PRO)
toast({ toast({
position: 'bottom-right', position: 'top-right',
status: 'success', status: 'success',
title: 'Upgrade success!', title: 'Upgrade success!',
description: `Workspace upgraded to ${toTitleCase(newPlan)} 🎉`, description: `Workspace upgraded to ${toTitleCase(newPlan)} 🎉`,
}) })
// eslint-disable-next-line react-hooks/exhaustive-deps }, [query.stripe])
}, [isReady])
const typebotId = query.typebotId?.toString() const typebotId = query.typebotId?.toString()
@ -54,21 +53,13 @@ const App = ({
<ChakraProvider theme={customTheme}> <ChakraProvider theme={customTheme}>
<SessionProvider session={session}> <SessionProvider session={session}>
<UserProvider> <UserProvider>
{typebotId ? (
<TypebotProvider typebotId={typebotId}> <TypebotProvider typebotId={typebotId}>
<WorkspaceProvider typebotId={typebotId}> <WorkspaceProvider typebotId={typebotId}>
<Component />
<SupportBubble />
<NewVersionPopup />
</WorkspaceProvider>
</TypebotProvider>
) : (
<WorkspaceProvider>
<Component {...pageProps} /> <Component {...pageProps} />
<SupportBubble /> <SupportBubble />
<NewVersionPopup /> <NewVersionPopup />
</WorkspaceProvider> </WorkspaceProvider>
)} </TypebotProvider>
</UserProvider> </UserProvider>
</SessionProvider> </SessionProvider>
</ChakraProvider> </ChakraProvider>