From 07dd7c5624558c203e5788bcdc51cc1dbdd3a9b4 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Thu, 14 May 2020 14:18:22 +0200 Subject: [PATCH] Signin (#6) * install redux and set authSlice * connect navBar to the sotre * create User type * install react-redux-firebase * bind to firebase * connect App to firebase auth; display splash screen while loading auth state * install firestore * install firestore * enable interactive form * signup page functional * fix navbar bug * extract useForm hook * extract Alert component * sign in page functional * commenting * log out function * add private route --- package.json | 1 + src/components/Alert.tsx | 15 + src/components/NavBar.tsx | 22 +- src/hooks/index.ts | 28 ++ src/models/User.ts | 16 +- src/pages/SignIn.tsx | 125 +++++-- src/pages/SignUp.tsx | 176 +++++++-- src/pages/__tests__/SignUp.spec.tsx | 7 + src/router/PrivateRoute.tsx | 48 +++ src/router/Router.tsx | 18 +- src/static/css/style.min.css | 548 +--------------------------- src/static/scss/_utils.scss | 2 +- yarn.lock | 7 + 13 files changed, 395 insertions(+), 618 deletions(-) create mode 100644 src/components/Alert.tsx create mode 100644 src/hooks/index.ts create mode 100644 src/pages/__tests__/SignUp.spec.tsx create mode 100644 src/router/PrivateRoute.tsx diff --git a/package.json b/package.json index 8b3c84b..31db85a 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "moment": "^2.25.3", "react": "^16.13.1", "react-dom": "^16.13.1", + "react-google-button": "^0.7.1", "react-redux": "^7.2.0", "react-redux-firebase": "^3.4.0", "react-router-dom": "^5.2.0", diff --git a/src/components/Alert.tsx b/src/components/Alert.tsx new file mode 100644 index 0000000..0aa6566 --- /dev/null +++ b/src/components/Alert.tsx @@ -0,0 +1,15 @@ +import React, {FC} from 'react'; +import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; +import {faExclamationTriangle} from '@fortawesome/free-solid-svg-icons'; + +interface IProps { + text: string; +} + +const Alert: FC = ({text}) => ( +
+ {text} +
+); + +export default Alert; diff --git a/src/components/NavBar.tsx b/src/components/NavBar.tsx index 9635b0a..d2622be 100644 --- a/src/components/NavBar.tsx +++ b/src/components/NavBar.tsx @@ -3,14 +3,17 @@ import React, {FC} from 'react'; import {Link} from 'react-router-dom'; import * as ROUTES from '../constants/routes'; //Redux +import {compose} from '@reduxjs/toolkit'; import {connect} from 'react-redux'; +import {withFirebase, WithFirebaseProps} from 'react-redux-firebase'; import {selectProfile} from '../store/firebase'; -// import {selectAuthState} from '../store/auth'; // Style import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faCode, faSignOutAlt, faUser} from '@fortawesome/free-solid-svg-icons'; +// Typing +import User from '../models/User'; -interface IProps { +interface IProps extends WithFirebaseProps { isEmpty: boolean; isLoaded: boolean; } @@ -18,7 +21,7 @@ interface IProps { /** * Main Navbar serves navigation routes. */ -const NavBar: FC = ({isEmpty, isLoaded}) => { +const NavBar: FC = ({firebase, isEmpty, isLoaded}) => { const publicLinks = (
  • @@ -58,7 +61,11 @@ const NavBar: FC = ({isEmpty, isLoaded}) => {
  • - + firebase.logout()} + > Log out @@ -67,7 +74,7 @@ const NavBar: FC = ({isEmpty, isLoaded}) => { ); /** Display appropriated links after loading given authenticated prop */ - const RenderLinks = !isLoaded && !isEmpty ? privateLinks : publicLinks; + const RenderLinks = isLoaded && !isEmpty ? privateLinks : publicLinks; return (