import React from "react" import { connect } from "react-redux" import { bindActionCreators } from "redux" import { loginUser } from "../../actions/users" function mapStateToProps(state) { return { isLogged: state.userStore.get("isLogged"), loading: state.userStore.get("loading"), }; } const mapDispatchToProps = (dispatch) => bindActionCreators({ loginUser }, dispatch) class UserLoginForm extends React.PureComponent { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); } componentWillReceiveProps(nextProps) { if (!nextProps.isLogged) { return } if (!nextProps.location.query.redirect) { // Redirect home nextProps.router.push("/"); } else { // Redirect to the previous page nextProps.router.push(nextProps.location.query.redirect); } } handleSubmit(e) { e.preventDefault(); if (this.props.loading) { return; } const username = this.refs.username.value; const password = this.refs.password.value; this.props.loginUser(username, password); } render() { return (

Log in


this.handleSubmit(e)}>


{this.props.loading && } {this.props.loading || }
); } } export default connect(mapStateToProps, mapDispatchToProps)(UserLoginForm);