2
0

fix(embed): 📝 Improve popup delay builder

This commit is contained in:
Baptiste Arnaud
2022-05-23 12:15:15 -07:00
parent 37dea9c403
commit 62b77e4905
10 changed files with 42 additions and 29 deletions

View File

@ -7,7 +7,7 @@ import { PopupParams } from 'typebot-js'
import { parseInitPopupCode, typebotJsHtml } from '../params' import { parseInitPopupCode, typebotJsHtml } from '../params'
type PopupEmbedCodeProps = { type PopupEmbedCodeProps = {
delay: number delay?: number
withStarterVariables?: boolean withStarterVariables?: boolean
onCopied?: () => void onCopied?: () => void
} }

View File

@ -8,6 +8,8 @@ import {
NumberInputStepper, NumberInputStepper,
NumberIncrementStepper, NumberIncrementStepper,
NumberDecrementStepper, NumberDecrementStepper,
Switch,
HStack,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { PopupParams } from 'typebot-js' import { PopupParams } from 'typebot-js'
@ -19,14 +21,15 @@ export const PopupEmbedSettings = ({
onUpdateSettings, onUpdateSettings,
...props ...props
}: PopupEmbedSettingsProps & StackProps) => { }: PopupEmbedSettingsProps & StackProps) => {
const [isEnabled, setIsEnabled] = useState(false)
const [inputValue, setInputValue] = useState(0) const [inputValue, setInputValue] = useState(0)
useEffect(() => { useEffect(() => {
onUpdateSettings({ onUpdateSettings({
delay: inputValue * 1000, delay: isEnabled ? inputValue * 1000 : undefined,
}) })
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [inputValue]) }, [inputValue, isEnabled])
return ( return (
<Stack {...props}> <Stack {...props}>
@ -37,18 +40,27 @@ export const PopupEmbedSettings = ({
</Flex> </Flex>
<Flex justify="space-between" align="center" mb="2"> <Flex justify="space-between" align="center" mb="2">
<p>Appearance delay</p> <HStack>
<NumberInput <p>Appearance delay</p>
onChange={(_, val) => setInputValue(val)} <Switch
value={inputValue} isChecked={isEnabled}
min={0} onChange={(e) => setIsEnabled(e.target.checked)}
> />
<NumberInputField /> </HStack>
<NumberInputStepper>
<NumberIncrementStepper /> {isEnabled && (
<NumberDecrementStepper /> <NumberInput
</NumberInputStepper> onChange={(_, val) => setInputValue(val)}
</NumberInput> value={inputValue}
min={0}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
)}
</Flex> </Flex>
</Stack> </Stack>
) )

View File

@ -7,6 +7,7 @@ import {
} from 'typebot-js' } from 'typebot-js'
import parserBabel from 'prettier/parser-babel' import parserBabel from 'prettier/parser-babel'
import prettier from 'prettier/standalone' import prettier from 'prettier/standalone'
import { isDefined } from 'utils'
const parseStringParam = (fieldName: string, fieldValue?: string) => const parseStringParam = (fieldName: string, fieldValue?: string) =>
fieldValue ? `${fieldName}: "${fieldValue}",` : `` fieldValue ? `${fieldName}: "${fieldValue}",` : ``
@ -14,7 +15,7 @@ const parseStringParam = (fieldName: string, fieldValue?: string) =>
const parseNonStringParam = ( const parseNonStringParam = (
fieldName: string, fieldName: string,
fieldValue?: number | boolean fieldValue?: number | boolean
) => (fieldValue ? `${fieldName}: ${fieldValue},` : ``) ) => (isDefined(fieldValue) ? `${fieldName}: ${fieldValue},` : ``)
const parseCustomDomain = (domain?: string): string => const parseCustomDomain = (domain?: string): string =>
parseStringParam('customDomain', domain) parseStringParam('customDomain', domain)

View File

@ -81,7 +81,7 @@ const StandardInstructions = ({ publicId }: Pick<ModalProps, 'publicId'>) => {
} }
const PopupInstructions = () => { const PopupInstructions = () => {
const [inputValue, setInputValue] = useState(0) const [inputValue, setInputValue] = useState<number>()
return ( return (
<OrderedList spacing={2} mb={4}> <OrderedList spacing={2} mb={4}>
@ -95,7 +95,7 @@ const PopupInstructions = () => {
Paste the code below: Paste the code below:
<PopupEmbedSettings <PopupEmbedSettings
my={4} my={4}
onUpdateSettings={(settings) => setInputValue(settings.delay ?? 0)} onUpdateSettings={(settings) => setInputValue(settings.delay)}
/> />
<PopupEmbedCode delay={inputValue} /> <PopupEmbedCode delay={inputValue} />
</ListItem> </ListItem>

View File

@ -48,7 +48,7 @@ const StandardInstructions = () => {
} }
const PopupInstructions = () => { const PopupInstructions = () => {
const [inputValue, setInputValue] = useState(0) const [inputValue, setInputValue] = useState<number>()
return ( return (
<Stack spacing={4}> <Stack spacing={4}>
@ -57,7 +57,7 @@ const PopupInstructions = () => {
</Text> </Text>
<PopupEmbedSettings <PopupEmbedSettings
mb={4} mb={4}
onUpdateSettings={(settings) => setInputValue(settings.delay ?? 0)} onUpdateSettings={(settings) => setInputValue(settings.delay)}
/> />
<PopupEmbedCode delay={inputValue} /> <PopupEmbedCode delay={inputValue} />
</Stack> </Stack>

View File

@ -33,7 +33,7 @@ export const NotionModal = ({
</ModalHeader> </ModalHeader>
<ModalCloseButton /> <ModalCloseButton />
<ModalBody> <ModalBody>
{!isPublished && <PublishFirstInfo />} {!isPublished && <PublishFirstInfo mb="4" />}
<OrderedList spacing={3}> <OrderedList spacing={3}>
<ListItem> <ListItem>
Type <Tag>/embed</Tag> Type <Tag>/embed</Tag>

View File

@ -48,13 +48,13 @@ const StandardInstructions = () => {
} }
const PopupInstructions = () => { const PopupInstructions = () => {
const [inputValue, setInputValue] = useState(0) const [inputValue, setInputValue] = useState<number>()
return ( return (
<Stack spacing={4}> <Stack spacing={4}>
<InstallPackageInstruction /> <InstallPackageInstruction />
<PopupEmbedSettings <PopupEmbedSettings
onUpdateSettings={(settings) => setInputValue(settings.delay ?? 0)} onUpdateSettings={(settings) => setInputValue(settings.delay)}
/> />
<Text>Initialize the typebot</Text> <Text>Initialize the typebot</Text>
<PopupReactCode withStarterVariables={true} delay={inputValue} /> <PopupReactCode withStarterVariables={true} delay={inputValue} />

View File

@ -96,7 +96,7 @@ const StandardInstructions = ({ publicId }: Pick<ModalProps, 'publicId'>) => {
} }
const PopupInstructions = () => { const PopupInstructions = () => {
const [inputValue, setInputValue] = useState(0) const [inputValue, setInputValue] = useState<number>()
return ( return (
<OrderedList spacing={2} mb={4}> <OrderedList spacing={2} mb={4}>
@ -109,7 +109,7 @@ const PopupInstructions = () => {
before the closing <Tag>head</Tag> tag: before the closing <Tag>head</Tag> tag:
<PopupEmbedSettings <PopupEmbedSettings
my="4" my="4"
onUpdateSettings={(settings) => setInputValue(settings.delay ?? 0)} onUpdateSettings={(settings) => setInputValue(settings.delay)}
/> />
<PopupEmbedCode delay={inputValue} /> <PopupEmbedCode delay={inputValue} />
</ListItem> </ListItem>

View File

@ -41,7 +41,7 @@ const StandardInstructions = () => (
) )
const PopupInstructions = () => { const PopupInstructions = () => {
const [inputValue, setInputValue] = useState(0) const [inputValue, setInputValue] = useState<number>()
return ( return (
<OrderedList spacing={2} mb={4}> <OrderedList spacing={2} mb={4}>
@ -52,7 +52,7 @@ const PopupInstructions = () => {
Add an <Tag>embed</Tag> element from the <Tag>components</Tag> Add an <Tag>embed</Tag> element from the <Tag>components</Tag>
section and paste this code: section and paste this code:
<PopupEmbedSettings <PopupEmbedSettings
onUpdateSettings={(settings) => setInputValue(settings.delay ?? 0)} onUpdateSettings={(settings) => setInputValue(settings.delay)}
my={4} my={4}
/> />
<PopupEmbedCode delay={inputValue} mt={4} /> <PopupEmbedCode delay={inputValue} mt={4} />

View File

@ -43,7 +43,7 @@ const StandardInstructions = () => {
} }
const PopupInstructions = () => { const PopupInstructions = () => {
const [inputValue, setInputValue] = useState(0) const [inputValue, setInputValue] = useState<number>()
return ( return (
<> <>
@ -60,7 +60,7 @@ const PopupInstructions = () => {
<ListItem> <ListItem>
Paste this snippet in the code box: Paste this snippet in the code box:
<PopupEmbedSettings <PopupEmbedSettings
onUpdateSettings={(settings) => setInputValue(settings.delay ?? 0)} onUpdateSettings={(settings) => setInputValue(settings.delay)}
my={4} my={4}
/> />
<PopupEmbedCode delay={inputValue} /> <PopupEmbedCode delay={inputValue} />