import React, { FC } from 'react' import { View } from 'react-native' import { styled } from '../../../styled' import { rv } from '../../../rv' import { themed } from '../../../theme/themed' import { BodyMedium, BodySmall } from '../../../text/Typography' import { TextLink } from '../../../text/TextLink' import { CountDown } from './CountDown' import { OneTimePasswordInput, OneTimePasswordInputProps } from './OneTimePasswordInput' export const OtpField: FC = (props) => { const [canResend, setCanResend] = React.useState(true) const [resetTimer, setResetTimer] = React.useState(false) return ( <_OneTimePasswordInput onTextChange={(text) => props.onTextChange?.(text)} onFilled={(text) => props.onFilled?.(text)} numberOfDigits={props.numberOfDigits} hasError={!!props.errorText} /> {props.errorText ?? ''} {props.resendText ?? '¿No lo recibió?'} {canResend ? { props.onResend() setResetTimer(!resetTimer) setCanResend(!canResend) }} > {props.resendButtonText ?? 'Reenviar código'} : setCanResend(true)} resetCount={resetTimer}/> } ) } const Actions = styled(View, { alignItems: 'center', marginTop: rv(50), }) const _OneTimePasswordInput = styled(OneTimePasswordInput, { marginBottom: rv(4), }) const OtpError = themed(BodySmall, ({ ds, resolve }) => ({ color: resolve(ds.ref.palette.error._50), paddingLeft: rv(4), })) interface OtpFieldProps extends OneTimePasswordInputProps { resendText?: string resendButtonText?: string errorText?: string resendCountDownInSecs: number onResend: () => void }