2022-01-12 09:32:16 +01:00
|
|
|
import {
|
|
|
|
IconButton,
|
|
|
|
Menu,
|
|
|
|
MenuButton,
|
|
|
|
MenuButtonProps,
|
|
|
|
MenuItem,
|
|
|
|
MenuList,
|
2022-04-08 14:30:46 -05:00
|
|
|
useDisclosure,
|
2022-01-12 09:32:16 +01:00
|
|
|
} from '@chakra-ui/react'
|
2022-02-04 19:00:08 +01:00
|
|
|
import assert from 'assert'
|
2022-04-08 14:30:46 -05:00
|
|
|
import { DownloadIcon, MoreVerticalIcon, SettingsIcon } from 'assets/icons'
|
2022-01-12 09:32:16 +01:00
|
|
|
import { useTypebot } from 'contexts/TypebotContext'
|
|
|
|
import React, { useState } from 'react'
|
|
|
|
import { parseDefaultPublicId } from 'services/typebots'
|
2022-04-08 14:30:46 -05:00
|
|
|
import { EditorSettingsModal } from './EditorSettingsModal'
|
2022-01-12 09:32:16 +01:00
|
|
|
|
|
|
|
export const BoardMenuButton = (props: MenuButtonProps) => {
|
|
|
|
const { typebot } = useTypebot()
|
|
|
|
const [isDownloading, setIsDownloading] = useState(false)
|
2022-04-08 14:30:46 -05:00
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
2022-01-12 09:32:16 +01:00
|
|
|
|
|
|
|
const downloadFlow = () => {
|
2022-02-04 19:00:08 +01:00
|
|
|
assert(typebot)
|
2022-01-12 09:32:16 +01:00
|
|
|
setIsDownloading(true)
|
|
|
|
const data =
|
|
|
|
'data:application/json;charset=utf-8,' +
|
|
|
|
encodeURIComponent(JSON.stringify(typebot))
|
|
|
|
const fileName = `typebot-export-${parseDefaultPublicId(
|
|
|
|
typebot.name,
|
|
|
|
typebot.id
|
|
|
|
)}.json`
|
|
|
|
const linkElement = document.createElement('a')
|
|
|
|
linkElement.setAttribute('href', data)
|
|
|
|
linkElement.setAttribute('download', fileName)
|
|
|
|
linkElement.click()
|
|
|
|
setIsDownloading(false)
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
<MenuButton
|
|
|
|
as={IconButton}
|
2022-04-08 14:30:46 -05:00
|
|
|
bgColor="white"
|
2022-01-12 09:32:16 +01:00
|
|
|
icon={<MoreVerticalIcon transform={'rotate(90deg)'} />}
|
|
|
|
isLoading={isDownloading}
|
2022-02-04 19:00:08 +01:00
|
|
|
size="sm"
|
2022-04-08 14:30:46 -05:00
|
|
|
shadow="lg"
|
2022-01-12 09:32:16 +01:00
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
<MenuList>
|
2022-04-08 14:30:46 -05:00
|
|
|
<MenuItem icon={<SettingsIcon />} onClick={onOpen}>
|
|
|
|
Editor settings
|
|
|
|
</MenuItem>
|
2022-01-12 09:32:16 +01:00
|
|
|
<MenuItem icon={<DownloadIcon />} onClick={downloadFlow}>
|
|
|
|
Export flow
|
|
|
|
</MenuItem>
|
|
|
|
</MenuList>
|
2022-04-08 14:30:46 -05:00
|
|
|
<EditorSettingsModal isOpen={isOpen} onClose={onClose} />
|
2022-01-12 09:32:16 +01:00
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|