diff --git a/js/components/Login.js b/js/components/Login.js index f447f90..bfa99e4 100644 --- a/js/components/Login.js +++ b/js/components/Login.js @@ -1,17 +1,9 @@ -import { - Container, - Card, - CardBody, - Form, - FormGroup, - Label, - Input, - Button -} from 'reactstrap'; -import React from 'react'; -import { connect } from 'react-redux'; +import {Card, CardBody, Container, Form, FormGroup, Input, Label} from 'reactstrap'; +import React from 'react'; +import {connect} from 'react-redux'; +import Router from 'next/router'; -import { login } from '../api'; +import {login} from '../api'; export function Login(props) { return ( @@ -65,6 +57,22 @@ const VisibleLoginErrorList = connect( mapStateToErrorMessages )(LoginErrorList); +class LoginSuccessRedirectComponent extends React.Component { + render() { + if (this.props.isSignedIn) { + Router.push('/'); + } + return null; + } +} + +const mapLoginState = (state) => { + const {isSignedIn} = state.userinfo; + return {isSignedIn}; +}; + +const LoginSuccessRedirect = connect(mapLoginState)(LoginSuccessRedirectComponent); + class LoginForm extends React.Component { constructor(props) { @@ -76,9 +84,14 @@ class LoginForm extends React.Component { }; } + tryLogin(event) { + event.preventDefault(); + login(this.state.email, this.state.password); + } + render() { return ( -
); }