@@ -2,11 +2,11 @@ import Botao from "@/components/Botao";
22import FieldInput from "@/components/FieldInput" ;
33import Form from "@/components/Form" ;
44import { MessageError } from "@/components/MessageError" ;
5- import { createUser } from "@/store/reducers/usuario" ;
5+ import { AppDispatch } from "@/store" ;
6+ import { addNewUser } from "@/store/reducers/usuario" ;
67import { ContainerForm , FieldsetForm , LegendForm } from "@/styles/forms" ;
78import { RootState } from "@/types/store" ;
89import { Usuario } from "@/types/usuarios" ;
9- import { getStorage } from "@/utils/starage" ;
1010import { useEffect } from "react" ;
1111import { useForm } from "react-hook-form" ;
1212import { useDispatch , useSelector } from "react-redux" ;
@@ -31,22 +31,19 @@ const FormRegister = () => {
3131 const user = useSelector ( ( state : RootState ) => state . usuario ) ;
3232 const cart = useSelector ( ( state : RootState ) => state . carrinho ) ;
3333 const navigate = useNavigate ( ) ;
34- const dispatch = useDispatch ( ) ;
34+ const dispatch = useDispatch < AppDispatch > ( ) ;
3535 const password = watch ( "password" ) ;
3636
3737 const checkPassword = {
3838 minLength : ( val : string | undefined ) =>
39- ( val ?. length ?? 0 ) >= 6 || "O campo senha deve ter pelo menos 6 caracteres" ,
40- checkEmpty : ( val : string | undefined ) => ! ! val || "O campo senha deve ser preenchido" ,
39+ ( val ?. length ?? 0 ) >= 6 ||
40+ "O campo senha deve ter pelo menos 6 caracteres" ,
41+ checkEmpty : ( val : string | undefined ) =>
42+ ! ! val || "O campo senha deve ser preenchido" ,
4143 validatePassword : ( val : string | undefined ) =>
4244 val === password || "As senhas devem ser iguais" ,
4345 } ;
4446 const checkEmail = {
45- emailUsed : ( val : string ) => {
46- const usuarios : Usuario [ ] = JSON . parse ( getStorage ( "user" ) || "[]" ) ;
47- const user = usuarios . find ( ( use ) => use . email === val ) ;
48- return ! user || "Email ja cadastrado" ;
49- } ,
5047 emailEmpty : ( val : string ) => ! ! val || "Verifique seu email" ,
5148 isEmailValid : ( val : string ) => {
5249 return (
@@ -69,7 +66,13 @@ const FormRegister = () => {
6966 } , [ isSubmitSuccessful , reset , user , cart , navigate ] ) ;
7067
7168 const submit = ( data : Usuario ) => {
72- dispatch ( createUser ( data ) ) ;
69+ dispatch (
70+ addNewUser ( {
71+ email : data . email ,
72+ nome : data . nome ,
73+ password : data . password ,
74+ } )
75+ ) ;
7376 } ;
7477
7578 return (
0 commit comments