diff --git a/src/pages/SignUp/SignUpForm/index.tsx b/src/pages/SignUp/SignUpForm/index.tsx index 69e4b5f..bb473f1 100644 --- a/src/pages/SignUp/SignUpForm/index.tsx +++ b/src/pages/SignUp/SignUpForm/index.tsx @@ -6,6 +6,7 @@ import { useForm } from 'react-hook-form'; import { PasswordInput } from '../../../components/ui/password-input'; import { Button } from '../../../components/ui/button'; import { Field } from '../../../components/ui/field'; +import { formatPhoneNumber } from './phoneformat'; interface FormValues { firstName: string; @@ -25,11 +26,9 @@ function SignUpForm() { handleSubmit, formState: { errors, isValid }, watch, + trigger, } = useForm(); - - - const { signUp, isAuthenticated } = useAuth(); const onSubmit = handleSubmit(async (data: FormValues) => { @@ -78,21 +77,29 @@ function SignUpForm() { message: "E-mail inválido." } })} + onChange={(e) => { + register('email').onChange(e); + trigger('email'); + }} /> - - - + { + const onlyNumbers = value.replace(/\D/g, ''); + return onlyNumbers.length === 11 || "Telefone inválido."; + } + })} + onChange={(e) => { + const formatted = formatPhoneNumber(e.target.value); + e.target.value = formatted; + register('phone').onChange(e); + trigger('phone'); + }} +/> + - - value === watch('password') || "As senhas não correspondem." - })} - /> + + value === watch('password') || "As senhas não correspondem." + })} + onChange={(e) => { + register('passwordConfirmation').onChange(e); + trigger('passwordConfirmation'); + }} + /> + +