import React, { FC, useRef } from 'react' import { Alert, Box, Button, Input } from '@vtex/store-ui' import { useIntl } from '@vtex/gatsby-plugin-i18n' import { State } from './state' interface Props { variant: string onSubmit: ( email: string, password: string, confirmPassword: string ) => Promise onBack: () => void state: State } const SignUpForm: FC = ({ variant, onSubmit, onBack, state: { state, email }, }) => { const { formatMessage } = useIntl() const code = useRef(null) const password = useRef(null) const confirmPwd = useRef(null) return ( <> {formatMessage({ id: 'login.page.emailAndPassword.signUpForm.title', defaultMessage: 'Validate email and create new password', })} {formatMessage( { id: 'login.page.emailAndPassword.signUpForm.subTitle', defaultMessage: 'Insert the code we sent to the email {email} and create a new password', }, { email, } )} { e.preventDefault() onSubmit( code.current?.value ?? '', password.current?.value ?? '', confirmPwd.current?.value ?? '' ) }} variant={variant} > {state === 'signUpForm.invalidAccessCodeInput' && ( {formatMessage({ id: 'login.page.emailAndPassword.signUpForm.invalidAccessCodeInput', defaultMessage: 'Invalid access code', })} )} {state === 'signUpForm.invalidPassword' && ( {formatMessage({ id: 'login.page.emailAndPassword.signUpForm.invalidPassword', defaultMessage: 'Invalid password. Your password needs to have at least eight digits, one lower case and one upper case letter, with at least one digit', })} )} {state === 'signUpForm.passwordDoNotMatch' && ( {formatMessage({ id: 'login.page.emailAndPassword.signUpForm.passwordDoNotMatch', defaultMessage: 'Passwords do not match', })} )} {state === 'signUpForm.error' && ( {formatMessage({ id: 'login.page.emailAndPassword.signUpForm.error', defaultMessage: 'Signing in failed. Please try again later', })} )} ) } export default SignUpForm