feat(inputs): ✨ Add Phone number input
This commit is contained in:
@ -56,6 +56,7 @@ const InputChatStep = ({
|
||||
case InputStepType.NUMBER:
|
||||
case InputStepType.EMAIL:
|
||||
case InputStepType.URL:
|
||||
case InputStepType.PHONE:
|
||||
return <TextForm step={step} onSubmit={handleSubmit} />
|
||||
case InputStepType.DATE:
|
||||
return <DateForm options={step.options} onSubmit={handleSubmit} />
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {
|
||||
EmailInputStep,
|
||||
NumberInputStep,
|
||||
PhoneNumberInputStep,
|
||||
TextInputStep,
|
||||
UrlInputStep,
|
||||
} from 'models'
|
||||
@ -9,7 +10,12 @@ import { SendButton } from '../SendButton'
|
||||
import { TextInput } from './TextInputContent'
|
||||
|
||||
type TextFormProps = {
|
||||
step: TextInputStep | EmailInputStep | NumberInputStep | UrlInputStep
|
||||
step:
|
||||
| TextInputStep
|
||||
| EmailInputStep
|
||||
| NumberInputStep
|
||||
| UrlInputStep
|
||||
| PhoneNumberInputStep
|
||||
onSubmit: (value: string) => void
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
NumberInputStep,
|
||||
InputStepType,
|
||||
UrlInputStep,
|
||||
PhoneNumberInputStep,
|
||||
} from 'models'
|
||||
import React, {
|
||||
ChangeEvent,
|
||||
@ -12,14 +13,20 @@ import React, {
|
||||
useEffect,
|
||||
useRef,
|
||||
} from 'react'
|
||||
import PhoneInput, { Value } from 'react-phone-number-input'
|
||||
|
||||
type TextInputProps = {
|
||||
step: TextInputStep | EmailInputStep | NumberInputStep | UrlInputStep
|
||||
step:
|
||||
| TextInputStep
|
||||
| EmailInputStep
|
||||
| NumberInputStep
|
||||
| UrlInputStep
|
||||
| PhoneNumberInputStep
|
||||
onChange: (value: string) => void
|
||||
}
|
||||
|
||||
export const TextInput = ({ step, onChange }: TextInputProps) => {
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const inputRef = useRef<any>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!inputRef.current) return
|
||||
@ -30,6 +37,10 @@ export const TextInput = ({ step, onChange }: TextInputProps) => {
|
||||
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
|
||||
) => onChange(e.target.value)
|
||||
|
||||
const handlePhoneNumberChange = (value?: Value | undefined) => {
|
||||
onChange(value as string)
|
||||
}
|
||||
|
||||
switch (step.type) {
|
||||
case InputStepType.TEXT: {
|
||||
return step.options?.isLong ? (
|
||||
@ -88,6 +99,17 @@ export const TextInput = ({ step, onChange }: TextInputProps) => {
|
||||
/>
|
||||
)
|
||||
}
|
||||
case InputStepType.PHONE: {
|
||||
return (
|
||||
<PhoneInput
|
||||
ref={inputRef}
|
||||
onChange={handlePhoneNumberChange}
|
||||
placeholder={
|
||||
step.options?.labels?.placeholder ?? 'Your phone number...'
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user