diff --git a/TODO.md b/TODO.md index dd58467..1e28437 100644 --- a/TODO.md +++ b/TODO.md @@ -3,5 +3,6 @@ - [ ] Doc - [ ] Tests - [ ] PropTypes +- [ ] Material UI - [ ] AuthSlice - [ ] Redux thunk for validation diff --git a/client/src/pages/SignUp/index.jsx b/client/src/pages/SignUp/index.jsx index d507f69..3a98e13 100644 --- a/client/src/pages/SignUp/index.jsx +++ b/client/src/pages/SignUp/index.jsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { Link } from "react-router-dom"; +import { Link, withRouter } from "react-router-dom"; import { Button, Form, FormGroup, Label, Input, Container } from "reactstrap"; import * as ROUTES from "../../constants/routes"; import { useFirebase } from "../../services/auth"; @@ -18,6 +18,9 @@ const useStyles = () => ({ }, }); +/** + * Page's layout + */ export default function SignUpPage() { const styles = useStyles(); return ( @@ -28,7 +31,10 @@ export default function SignUpPage() { ); } -export const SignUpForm = () => { +/** + * Holds the form state and validates the form. + */ +const SignUpFormBase = (props) => { const [userName, setUserName] = useState(""); const [email, setEmail] = useState(""); const [password1, setPassword1] = useState(""); @@ -37,9 +43,23 @@ export const SignUpForm = () => { const auth = useFirebase(); + const cleanFields = () => { + setUserName(""); + setEmail(""); + setPassword1(""); + setPassword2(""); + setError(null); + }; + const handleSubmit = (e) => { e.preventDefault(); - auth.signInWithGoogle().then((res) => console.log(res.user)); + auth + .createUserWithEmailAndPassword(email, password1) + .then(() => { + cleanFields(); + props.history.push(ROUTES.APP); + }) + .catch((err) => setError(err)); }; const isInvalid = @@ -99,6 +119,11 @@ const InputField = ({ id, label, set, type = "text" }) => { ); }; +/** + * Sign Up form final component. withRouter allows redirections. + */ +export const SignUpForm = withRouter(SignUpFormBase); + export const SignUpLink = () => (

Don't have an account yet? Sign Up diff --git a/client/src/services/auth/firebase.js b/client/src/services/auth/firebase.js index cc53f77..f2c51d6 100644 --- a/client/src/services/auth/firebase.js +++ b/client/src/services/auth/firebase.js @@ -23,6 +23,7 @@ export default class Firebase { } provider = new app.auth.GoogleAuthProvider(); + signInWithGoogle = () => this.auth.signInWithPopup(this.provider); createUserWithEmailAndPassword = (email, password) =>