2
0

feat(inputs): Add Phone number input

This commit is contained in:
Baptiste Arnaud
2022-01-10 10:43:27 +01:00
parent 8cba7ff37b
commit b20bcb1408
19 changed files with 218 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import {
FlagIcon,
GlobeIcon,
NumberIcon,
PhoneIcon,
TextIcon,
} from 'assets/icons'
import { BubbleStepType, InputStepType, StepType } from 'models'
@ -32,6 +33,9 @@ export const StepIcon = ({ type }: StepIconProps) => {
case InputStepType.DATE: {
return <CalendarIcon />
}
case InputStepType.PHONE: {
return <PhoneIcon />
}
case 'start': {
return <FlagIcon />
}

View File

@ -22,6 +22,9 @@ export const StepTypeLabel = ({ type }: Props) => {
case InputStepType.DATE: {
return <Text>Date</Text>
}
case InputStepType.PHONE: {
return <Text>Phone</Text>
}
default: {
return <></>
}

View File

@ -8,6 +8,7 @@ import {
UrlInputSettingsBody,
DateInputSettingsBody,
} from './bodies'
import { PhoneNumberSettingsBody } from './bodies/PhoneNumberSettingsBody'
type Props = {
step: Step
@ -71,6 +72,14 @@ const SettingsPopoverBodyContent = ({ step }: Props) => {
/>
)
}
case InputStepType.PHONE: {
return (
<PhoneNumberSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
default: {
return <></>
}

View File

@ -0,0 +1,46 @@
import { FormLabel, Stack } from '@chakra-ui/react'
import { DebouncedInput } from 'components/shared/DebouncedInput'
import { EmailInputOptions } from 'models'
import React from 'react'
type PhoneNumberSettingsBodyProps = {
options?: EmailInputOptions
onOptionsChange: (options: EmailInputOptions) => void
}
export const PhoneNumberSettingsBody = ({
options,
onOptionsChange,
}: PhoneNumberSettingsBodyProps) => {
const handlePlaceholderChange = (placeholder: string) =>
onOptionsChange({ ...options, labels: { ...options?.labels, placeholder } })
const handleButtonLabelChange = (button: string) =>
onOptionsChange({ ...options, labels: { ...options?.labels, button } })
return (
<Stack spacing={4}>
<Stack>
<FormLabel mb="0" htmlFor="placeholder">
Placeholder:
</FormLabel>
<DebouncedInput
id="placeholder"
initialValue={options?.labels?.placeholder ?? 'Your phone number...'}
delay={100}
onChange={handlePlaceholderChange}
/>
</Stack>
<Stack>
<FormLabel mb="0" htmlFor="button">
Button label:
</FormLabel>
<DebouncedInput
id="button"
initialValue={options?.labels?.button ?? 'Send'}
delay={100}
onChange={handleButtonLabelChange}
/>
</Stack>
</Stack>
)
}

View File

@ -53,6 +53,13 @@ export const StepNodeLabel = (props: Step | StartStep) => {
</Text>
)
}
case InputStepType.PHONE: {
return (
<Text color={'gray.500'}>
{props.options?.labels?.placeholder ?? 'Your phone number...'}
</Text>
)
}
case 'start': {
return <Text>{props.label}</Text>
}