2023-03-03 09:01:11 +01:00
|
|
|
import { TextInput, NumberInput } from '@/components/inputs'
|
2023-09-22 17:12:15 +02:00
|
|
|
import { Stack, Text } from '@chakra-ui/react'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { EmbedBubbleContent } from '@typebot.io/schemas'
|
|
|
|
import { sanitizeUrl } from '@typebot.io/lib'
|
2023-10-27 09:23:50 +02:00
|
|
|
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) => {
|
2023-10-27 09:23:50 +02:00
|
|
|
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 })
|
|
|
|
}
|
|
|
|
|
2023-02-19 09:53:57 +01:00
|
|
|
const handleHeightChange = (height?: EmbedBubbleContent['height']) =>
|
2022-03-23 12:01:35 +01:00
|
|
|
height && onSubmit({ ...content, height })
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Stack p="2" spacing={6}>
|
|
|
|
<Stack>
|
2023-03-03 09:01:11 +01:00
|
|
|
<TextInput
|
2023-10-27 09:23:50 +02:00
|
|
|
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">
|
2023-10-27 09:23:50 +02:00
|
|
|
{t('editor.blocks.bubbles.embed.settings.worksWith.text')}
|
2022-03-23 12:01:35 +01:00
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
|
2023-09-22 17:12:15 +02:00
|
|
|
<NumberInput
|
|
|
|
label="Height:"
|
|
|
|
defaultValue={content?.height}
|
|
|
|
onValueChange={handleHeightChange}
|
2023-10-27 09:23:50 +02:00
|
|
|
suffix={t('editor.blocks.bubbles.embed.settings.numberInput.unit')}
|
2023-09-22 17:12:15 +02:00
|
|
|
width="150px"
|
|
|
|
/>
|
2022-03-23 12:01:35 +01:00
|
|
|
</Stack>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const extractUrlFromIframe = (iframe: string) =>
|
|
|
|
[...iframe.matchAll(/src="([^"]+)"/g)][0][1]
|