-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inputs): ✨ Add Export flow menu button
- Loading branch information
1 parent
c02c61c
commit 659f50e
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
) | ||
} |