feat(inputs): ✨ Add Export flow menu button
This commit is contained in:
@ -6,6 +6,7 @@ import { StepTypesList } from './StepTypesList'
|
|||||||
import { PreviewDrawer } from './preview/PreviewDrawer'
|
import { PreviewDrawer } from './preview/PreviewDrawer'
|
||||||
import { RightPanel, useEditor } from 'contexts/EditorContext'
|
import { RightPanel, useEditor } from 'contexts/EditorContext'
|
||||||
import { GraphProvider } from 'contexts/GraphContext'
|
import { GraphProvider } from 'contexts/GraphContext'
|
||||||
|
import { BoardMenuButton } from './BoardMenuButton'
|
||||||
|
|
||||||
export const Board = () => {
|
export const Board = () => {
|
||||||
const { rightPanel } = useEditor()
|
const { rightPanel } = useEditor()
|
||||||
@ -16,6 +17,7 @@ export const Board = () => {
|
|||||||
<GraphProvider>
|
<GraphProvider>
|
||||||
<Graph flex="1" />
|
<Graph flex="1" />
|
||||||
{rightPanel === RightPanel.PREVIEW && <PreviewDrawer />}
|
{rightPanel === RightPanel.PREVIEW && <PreviewDrawer />}
|
||||||
|
<BoardMenuButton pos="absolute" right="20px" top="20px" />
|
||||||
</GraphProvider>
|
</GraphProvider>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
49
apps/builder/components/board/BoardMenuButton.tsx
Normal file
49
apps/builder/components/board/BoardMenuButton.tsx
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import {
|
||||||
|
IconButton,
|
||||||
|
Menu,
|
||||||
|
MenuButton,
|
||||||
|
MenuButtonProps,
|
||||||
|
MenuItem,
|
||||||
|
MenuList,
|
||||||
|
} from '@chakra-ui/react'
|
||||||
|
import { DownloadIcon, MoreVerticalIcon } from 'assets/icons'
|
||||||
|
import { useTypebot } from 'contexts/TypebotContext'
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
import { parseDefaultPublicId } from 'services/typebots'
|
||||||
|
|
||||||
|
export const BoardMenuButton = (props: MenuButtonProps) => {
|
||||||
|
const { typebot } = useTypebot()
|
||||||
|
const [isDownloading, setIsDownloading] = useState(false)
|
||||||
|
|
||||||
|
const downloadFlow = () => {
|
||||||
|
if (!typebot) return
|
||||||
|
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}
|
||||||
|
icon={<MoreVerticalIcon transform={'rotate(90deg)'} />}
|
||||||
|
isLoading={isDownloading}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
<MenuList>
|
||||||
|
<MenuItem icon={<DownloadIcon />} onClick={downloadFlow}>
|
||||||
|
Export flow
|
||||||
|
</MenuItem>
|
||||||
|
</MenuList>
|
||||||
|
</Menu>
|
||||||
|
)
|
||||||
|
}
|
Reference in New Issue
Block a user