2022-03-01 07:13:09 +01:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
HStack,
|
|
|
|
IconButton,
|
|
|
|
Stack,
|
|
|
|
Tooltip,
|
|
|
|
Text,
|
|
|
|
Menu,
|
|
|
|
MenuButton,
|
|
|
|
MenuList,
|
|
|
|
MenuItem,
|
|
|
|
} from '@chakra-ui/react'
|
|
|
|
import { ChevronLeftIcon } from 'assets/icons'
|
2022-01-06 09:40:56 +01:00
|
|
|
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
|
2022-03-01 07:13:09 +01:00
|
|
|
import { timeSince } from 'services/utils'
|
|
|
|
import { isNotDefined } from 'utils'
|
2021-12-22 14:59:07 +01:00
|
|
|
|
|
|
|
export const PublishButton = () => {
|
2022-03-01 07:13:09 +01:00
|
|
|
const {
|
|
|
|
isPublishing,
|
|
|
|
isPublished,
|
|
|
|
publishTypebot,
|
|
|
|
publishedTypebot,
|
|
|
|
restorePublishedTypebot,
|
|
|
|
} = useTypebot()
|
2021-12-23 16:31:56 +01:00
|
|
|
|
2021-12-22 14:59:07 +01:00
|
|
|
return (
|
2022-03-01 07:13:09 +01:00
|
|
|
<HStack spacing="1px">
|
|
|
|
<Tooltip
|
|
|
|
borderRadius="md"
|
|
|
|
hasArrow
|
|
|
|
placement="bottom-end"
|
|
|
|
label={
|
|
|
|
<Stack>
|
|
|
|
<Text>There are non published changes.</Text>
|
|
|
|
<Text fontStyle="italic">
|
|
|
|
Published version from{' '}
|
|
|
|
{publishedTypebot &&
|
|
|
|
timeSince(publishedTypebot.updatedAt.toString())}{' '}
|
|
|
|
ago
|
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
}
|
|
|
|
isDisabled={isNotDefined(publishedTypebot)}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
colorScheme="blue"
|
|
|
|
isLoading={isPublishing}
|
|
|
|
isDisabled={isPublished}
|
|
|
|
onClick={publishTypebot}
|
|
|
|
borderRightRadius={publishedTypebot && !isPublished ? 0 : undefined}
|
|
|
|
>
|
|
|
|
{isPublished ? 'Published' : 'Publish'}
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
{publishedTypebot && !isPublished && (
|
|
|
|
<Menu>
|
|
|
|
<MenuButton
|
|
|
|
as={IconButton}
|
|
|
|
colorScheme="blue"
|
|
|
|
borderLeftRadius={0}
|
|
|
|
icon={<ChevronLeftIcon transform="rotate(-90deg)" />}
|
|
|
|
aria-label="Show published version"
|
|
|
|
/>
|
|
|
|
<MenuList>
|
|
|
|
<MenuItem onClick={restorePublishedTypebot}>
|
|
|
|
Restore published version
|
|
|
|
</MenuItem>
|
|
|
|
</MenuList>
|
|
|
|
</Menu>
|
|
|
|
)}
|
|
|
|
</HStack>
|
2021-12-22 14:59:07 +01:00
|
|
|
)
|
|
|
|
}
|