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 { 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 { sendRequest } from 'utils'
import { PackageIcon } from './icons'
@ -42,43 +50,51 @@ export const NewVersionPopup = () => {
window.location.reload()
}
if (!isNewVersionAvailable) return null
return (
<Stack
pos="fixed"
bottom="18px"
left="18px"
bgColor="blue.400"
p="4"
px="4"
rounded="lg"
shadow="lg"
zIndex={10}
borderWidth="1px"
borderColor="blue.300"
maxW="320px"
>
<HStack spacing={3}>
<Stack spacing={4}>
<Stack spacing={1} color="white">
<HStack>
<PackageIcon />{' '}
<Text fontWeight="bold">New version available!</Text>
</HStack>
<DarkMode>
<SlideFade
in={isNewVersionAvailable}
offsetY="20px"
style={{
position: 'fixed',
bottom: '18px',
left: '18px',
zIndex: 42,
}}
unmountOnExit
>
<Stack
bgColor="blue.400"
p="4"
px="4"
rounded="lg"
shadow="lg"
borderWidth="1px"
borderColor="blue.300"
maxW="320px"
>
<HStack spacing={3}>
<Stack spacing={4} color="white">
<Stack spacing={1}>
<HStack>
<PackageIcon />{' '}
<Text fontWeight="bold">New version available!</Text>
</HStack>
<Text fontSize="sm" color="gray.100">
An improved version of Typebot is available. Please reload now to
upgrade.
</Text>
</Stack>
<Flex justifyContent="flex-end">
<Button size="sm" onClick={saveAndReload}>
{typebot?.id ? 'Save and reload' : 'Reload'}
</Button>
</Flex>
<Text fontSize="sm" color="gray.100">
An improved version of Typebot is available. Please reload now
to upgrade.
</Text>
</Stack>
<Flex justifyContent="flex-end">
<Button size="sm" onClick={saveAndReload}>
{typebot?.id ? 'Save and reload' : 'Reload'}
</Button>
</Flex>
</Stack>
</HStack>
</Stack>
</HStack>
</Stack>
</SlideFade>
</DarkMode>
)
}

View File

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

View File

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

View File

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