Skip to content

Commit

Permalink
♻️ Better phone input props pass
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 27, 2023
1 parent 2fc78a5 commit 73ef12d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
5 changes: 4 additions & 1 deletion packages/js/src/components/InputChatBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ const Input = (props: {
</Match>
<Match when={props.block.type === InputBlockType.PHONE}>
<PhoneInput
block={props.block as PhoneNumberInputBlock}
labels={(props.block as PhoneNumberInputBlock).options.labels}
defaultCountryCode={
(props.block as PhoneNumberInputBlock).options.defaultCountryCode
}
defaultValue={getPrefilledValue()}
onSubmit={onSubmit}
hasGuestAvatar={props.hasGuestAvatar}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ import { ShortTextInput } from '@/components'
import { SendButton } from '@/components/SendButton'
import { InputSubmitContent } from '@/types'
import { isMobile } from '@/utils/isMobileSignal'
import type { PhoneNumberInputBlock } from 'models'
import type { PhoneNumberInputOptions } from 'models'
import { createSignal, For, onMount } from 'solid-js'
import { isEmpty } from 'utils'
import { phoneCountries } from 'utils/phoneCountries'

type PhoneInputProps = {
block: PhoneNumberInputBlock
type PhoneInputProps = Pick<
PhoneNumberInputOptions,
'labels' | 'defaultCountryCode'
> & {
defaultValue?: string
onSubmit: (value: InputSubmitContent) => void
hasGuestAvatar: boolean
}

export const PhoneInput = (props: PhoneInputProps) => {
// eslint-disable-next-line solid/reactivity
const defaultCountryCode = props.block.options.defaultCountryCode

const [selectedCountryCode, setSelectedCountryCode] = createSignal(
isEmpty(defaultCountryCode) ? 'INT' : defaultCountryCode
isEmpty(props.defaultCountryCode) ? 'INT' : props.defaultCountryCode
)
const [inputValue, setInputValue] = createSignal(props.defaultValue ?? '')
let inputRef: HTMLInputElement | undefined
Expand Down Expand Up @@ -102,9 +101,7 @@ export const PhoneInput = (props: PhoneInputProps) => {
ref={inputRef}
value={inputValue()}
onInput={handleInput}
placeholder={
props.block.options.labels.placeholder ?? 'Your phone number...'
}
placeholder={props.labels.placeholder ?? 'Your phone number...'}
autofocus={!isMobile()}
/>
</div>
Expand All @@ -115,7 +112,7 @@ export const PhoneInput = (props: PhoneInputProps) => {
class="my-2 ml-2"
on:click={submit}
>
{props.block.options?.labels?.button ?? 'Send'}
{props.labels?.button ?? 'Send'}
</SendButton>
</div>
)
Expand Down

0 comments on commit 73ef12d

Please sign in to comment.