2023-03-15 11:51:30 +01:00
|
|
|
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
2023-02-27 09:31:11 +01:00
|
|
|
import { trpc } from '@/lib/trpc'
|
2023-02-22 16:59:04 +01:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
DarkMode,
|
|
|
|
|
Flex,
|
|
|
|
|
HStack,
|
|
|
|
|
SlideFade,
|
|
|
|
|
Stack,
|
|
|
|
|
Text,
|
|
|
|
|
} from '@chakra-ui/react'
|
2023-02-15 18:05:19 +01:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
import { PackageIcon } from './icons'
|
|
|
|
|
|
|
|
|
|
export const NewVersionPopup = () => {
|
2023-02-17 16:30:02 +01:00
|
|
|
const { typebot, save } = useTypebot()
|
2023-02-27 09:31:11 +01:00
|
|
|
const [isReloading, setIsReloading] = useState(false)
|
|
|
|
|
const { data } = trpc.getAppVersionProcedure.useQuery()
|
2023-02-15 18:05:19 +01:00
|
|
|
const [currentVersion, setCurrentVersion] = useState<string>()
|
|
|
|
|
const [isNewVersionAvailable, setIsNewVersionAvailable] = useState(false)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-02-27 09:31:11 +01:00
|
|
|
if (!data?.commitSha) return
|
|
|
|
|
if (currentVersion === data.commitSha) return
|
|
|
|
|
setCurrentVersion(data.commitSha)
|
|
|
|
|
if (currentVersion === undefined) return
|
|
|
|
|
setIsNewVersionAvailable(true)
|
|
|
|
|
}, [data, currentVersion])
|
2023-02-15 18:05:19 +01:00
|
|
|
|
|
|
|
|
const saveAndReload = async () => {
|
|
|
|
|
if (isReloading) return
|
|
|
|
|
setIsReloading(true)
|
|
|
|
|
if (save) await save()
|
|
|
|
|
window.location.reload()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2023-02-22 16:59:04 +01:00
|
|
|
<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>
|
2023-02-17 16:30:02 +01:00
|
|
|
|
2023-02-22 16:59:04 +01:00
|
|
|
<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>
|
2023-02-15 18:05:19 +01:00
|
|
|
</Stack>
|
2023-02-22 16:59:04 +01:00
|
|
|
</SlideFade>
|
|
|
|
|
</DarkMode>
|
2023-02-15 18:05:19 +01:00
|
|
|
)
|
|
|
|
|
}
|