2
0
Files
bot/apps/builder/src/features/blocks/bubbles/embed/components/EmbedUploadContent.tsx

52 lines
1.5 KiB
TypeScript
Raw Normal View History

import { TextInput, NumberInput } from '@/components/inputs'
import { Stack, Text } from '@chakra-ui/react'
import { EmbedBubbleContent } from '@typebot.io/schemas'
import { sanitizeUrl } from '@typebot.io/lib'
import { useTranslate } from '@tolgee/react'
2022-03-23 12:01:35 +01:00
type Props = {
content: EmbedBubbleContent
onSubmit: (content: EmbedBubbleContent) => void
}
export const EmbedUploadContent = ({ content, onSubmit }: Props) => {
const { t } = useTranslate()
2022-03-23 12:01:35 +01:00
const handleUrlChange = (url: string) => {
2022-03-24 10:12:49 +01:00
const iframeUrl = sanitizeUrl(
2022-03-23 12:01:35 +01:00
url.trim().startsWith('<iframe') ? extractUrlFromIframe(url) : url
)
onSubmit({ ...content, url: iframeUrl })
}
const handleHeightChange = (height?: EmbedBubbleContent['height']) =>
2022-03-23 12:01:35 +01:00
height && onSubmit({ ...content, height })
return (
<Stack p="2" spacing={6}>
<Stack>
<TextInput
placeholder={t(
'editor.blocks.bubbles.embed.settings.worksWith.placeholder'
)}
2022-03-23 12:01:35 +01:00
defaultValue={content?.url ?? ''}
onChange={handleUrlChange}
/>
<Text fontSize="sm" color="gray.400" textAlign="center">
{t('editor.blocks.bubbles.embed.settings.worksWith.text')}
2022-03-23 12:01:35 +01:00
</Text>
</Stack>
<NumberInput
label="Height:"
defaultValue={content?.height}
onValueChange={handleHeightChange}
suffix={t('editor.blocks.bubbles.embed.settings.numberInput.unit')}
width="150px"
/>
2022-03-23 12:01:35 +01:00
</Stack>
)
}
const extractUrlFromIframe = (iframe: string) =>
[...iframe.matchAll(/src="([^"]+)"/g)][0][1]