import * as React from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import I18n from 'i18n-js'; import Box from '../common/Box'; import Button from '../common/Button'; import { ITenantSignUpUserForm } from './TenantSignUpP'; import { DangerText } from '../common/CustomTexts'; import { getLabel, getValidationMessage } from '../../helpers/formUtils'; import { EMAIL_REGEX } from '../../constants/regex'; interface Props { currentStep: number; setCurrentStep(step: number): void; emailAuth: boolean; setEmailAuth(enabled: boolean): void; userData: ITenantSignUpUserForm; setUserData({}: ITenantSignUpUserForm): void; } const UserSignUpForm = ({ currentStep, setCurrentStep, emailAuth, setEmailAuth, userData, setUserData, }: Props) => { const { register, handleSubmit, setError, getValues, formState: { errors } } = useForm(); const onSubmit: SubmitHandler = data => { if (data.password !== data.passwordConfirmation) { setError('passwordConfirmation', I18n.t('signup.step1.validations.password_mismatch')); return; } setUserData({...data}); setCurrentStep(currentStep + 1); } return (

{ I18n.t('signup.step1.title') }

{ currentStep === 1 && !emailAuth && } { currentStep === 1 && emailAuth &&
{errors.fullName && getValidationMessage('required', 'user', 'full_name')}
{errors.email?.type === 'required' && getValidationMessage('required', 'user', 'email')} {errors.email?.type === 'pattern' && I18n.t('common.validations.email')}
{ errors.password && I18n.t('common.validations.password', { n: 6 }) }
{ errors.passwordConfirmation && I18n.t('common.validations.password_mismatch') }
} { currentStep === 2 &&

{userData.fullName} ({userData.email})

}
); } export default UserSignUpForm;