import { StackProps, Stack, Heading, HStack, Input, Flex, FormControl, FormLabel, NumberInput, NumberInputField, NumberInputStepper, NumberIncrementStepper, NumberDecrementStepper, Switch, Text, Image, } from '@chakra-ui/react' import { ColorPicker } from 'components/theme/GeneralSettings/ColorPicker' import { useTypebot } from 'contexts/TypebotContext' import { useUser } from 'contexts/UserContext' import { useState, useEffect } from 'react' import { BubbleParams } from 'typebot-js' type ChatEmbedSettingsProps = { onUpdateSettings: ( windowSettings: Pick ) => void } export const ChatEmbedSettings = ({ onUpdateSettings, ...props }: ChatEmbedSettingsProps & StackProps) => { const { user } = useUser() const { typebot } = useTypebot() const [proactiveMessageChecked, setProactiveMessageChecked] = useState(false) const [isCustomIconChecked, setIsCustomIconChecked] = useState(false) const [rememberProMessageChecked] = useState(true) const [customIconInputValue, setCustomIconInputValue] = useState('') const [inputValues, setInputValues] = useState({ messageDelay: '0', messageContent: 'I have a question for you!', avatarUrl: typebot?.theme.chat.hostAvatar?.url ?? user?.image ?? '', }) const [bubbleColor, setBubbleColor] = useState( typebot?.theme.chat.buttons.backgroundColor ?? '#0042DA' ) const [bubbleIconColor, setIconBubbleColor] = useState( typebot?.theme.chat.buttons.color ?? '#FFFFFF' ) useEffect(() => { if (proactiveMessageChecked) { onUpdateSettings({ button: { color: bubbleColor, iconUrl: isCustomIconChecked ? customIconInputValue : undefined, iconColor: bubbleIconColor === '#FFFFFF' ? undefined : bubbleIconColor, }, proactiveMessage: { delay: parseInt(inputValues.messageDelay) * 1000, textContent: inputValues.messageContent, avatarUrl: inputValues.avatarUrl, rememberClose: rememberProMessageChecked, }, }) } else { onUpdateSettings({ button: { color: bubbleColor, iconUrl: isCustomIconChecked ? customIconInputValue : undefined, iconColor: bubbleIconColor === '#FFFFFF' ? undefined : bubbleIconColor, }, proactiveMessage: undefined, }) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [ inputValues, bubbleColor, rememberProMessageChecked, customIconInputValue, bubbleIconColor, proactiveMessageChecked, isCustomIconChecked, ]) return ( Chat bubble settings Button color Icon color Custom button icon? setIsCustomIconChecked(!isCustomIconChecked)} isChecked={isCustomIconChecked} /> {isCustomIconChecked && ( <> Url: setCustomIconInputValue(e.target.value)} minW="0" /> )} Enable popup message? setProactiveMessageChecked(!proactiveMessageChecked) } isChecked={proactiveMessageChecked} /> {proactiveMessageChecked && ( <> {inputValues.avatarUrl && ( // eslint-disable-next-line jsx-a11y/alt-text )} {inputValues.messageContent} Appearance delay setInputValues({ ...inputValues, messageDelay, }) } value={inputValues.messageDelay} min={0} > Avatar URL setInputValues({ ...inputValues, avatarUrl: e.target.value, }) } value={inputValues.avatarUrl} placeholder={'Paste image link (.png, .jpg)'} /> Message content setInputValues({ ...inputValues, messageContent: e.target.value, }) } value={inputValues.messageContent} /> )} ) }