diff --git a/src/components/Input/Input.jsx b/src/components/Input/Input.jsx index de14460..8ed7446 100644 --- a/src/components/Input/Input.jsx +++ b/src/components/Input/Input.jsx @@ -10,6 +10,8 @@ function Input(props) { type={props.typeName} placeholder={props.placeholder} className={`${styles.input} ${props.bigger ? `${styles.bigger}` : ''}`} + onChange={props.handler} + name={props.name} /> ); diff --git a/src/pages/LogIn/LogIn.jsx b/src/pages/LogIn/LogIn.jsx index 1fadc79..c6aeb4c 100644 --- a/src/pages/LogIn/LogIn.jsx +++ b/src/pages/LogIn/LogIn.jsx @@ -63,13 +63,13 @@ export function LogIn() { } else { signInWithEmailAndPassword(auth, email, password) .then(() => { - push('/'); toast({ title: 'Logged', status: 'success', duration: 1500, isClosable: false, }); + push('/'); }) .catch((err) => { const error = err diff --git a/src/pages/SignIn/SignIn.jsx b/src/pages/SignIn/SignIn.jsx index 2c5dc65..415fca9 100644 --- a/src/pages/SignIn/SignIn.jsx +++ b/src/pages/SignIn/SignIn.jsx @@ -1,71 +1,152 @@ import React, { useState } from 'react'; -import { Link } from 'react-router-dom' +import { Link } from 'react-router-dom'; import { ButtonComponent } from '../../components/ButtonComponent/ButtonComponent'; import { Input } from '../../components/Input/Input'; -import styles from './SignIn.module.css' +import styles from './SignIn.module.css'; -import mangoimage from '../../assets/images/mango.svg' -import eye from '../../assets/images/showpassword.svg' -import eyeSlash from '../../assets/images/showpass.svg' +import mangoimage from '../../assets/images/mango.svg'; +import eye from '../../assets/images/showpassword.svg'; +import eyeSlash from '../../assets/images/showpass.svg'; +import { useToast } from '@chakra-ui/react'; +import { createUserWithEmailAndPassword, updateProfile } from 'firebase/auth'; +import { auth } from '../../firebase/firebaseConfig'; +import { useHistory } from 'react-router-dom/cjs/react-router-dom.min'; export function SignIn() { - const [showPass, setShowPass] = useState("password") + const [showPass, setShowPass] = useState('password'); + const [newUser, setNewUser] = useState({ + name: '', + lastName: '', + password: '', + email: '', + countryAndCity: '', + uuid: '', + }); + const { push } = useHistory(); + const toast = useToast(); function togglePass() { if (showPass === 'password') { - setShowPass('') - } - else { - setShowPass('password') + setShowPass(''); + } else { + setShowPass('password'); } } + const handlerSubmit = (e) => { + e.preventDefault(); + console.log(newUser); + if ( + !newUser.name || + !newUser.lastName || + !newUser.password || + !newUser.email + //|| !newUser.countryAndCity + ) { + return toast({ + title: `Complete los campos`, + status: 'error', + duration: 1500, + isClosable: false, + }); + } + console.log(newUser); + createUserWithEmailAndPassword(auth, newUser.email, newUser.password) + .then((userCredential) => { + const user = userCredential.user; + setNewUser({ ...newUser, uuid: user.uuid }); + console.log(user); + updateProfile(auth.currentUser, { + displayName: newUser.name + ' ' + newUser.lastName, + photoURL: '', + }) + .then(() => { + toast({ + title: 'Registered', + status: 'success', + duration: 1500, + isClosable: false, + }); + push('/'); + }) + .catch((error) => { + console.log(error); + }); + }) + .catch((err) => { + return toast({ + title: `${err}`, + status: 'error', + duration: 1500, + isClosable: false, + }); + }); + }; + const handlerChngInput = (e) => { + // console.log(e.target.value); + let { + target: { value, name }, + } = e; + e.target.value = value.trim().replaceAll(/\s/g, ''); + setNewUser({ ...newUser, [name]: e.target.value }); + console.log(newUser[name]); + }; return (
Mango
- mango + mango
MANGO
-
+ - showpass - showpass + showpass + showpass - +

- Ya tenés una cuenta? + Ya tenés una cuenta? -

- Login -
+
Login
-
); } -