Files
cnapp/src/modules/login/LoginContainer.js
T
nikolark 1c42c0c925 Login: Misc Improvements
Restyle with NativeBase components
Use DUSKEN_API_URL
Move redux handling stuff to LoginContainer
Add redux-logger
2017-08-09 00:44:56 +02:00

43 lines
1.2 KiB
JavaScript

import React, {Component} from 'react';
import {connect} from "react-redux";
import Login from "./Login";
import {requestLogin} from "../../actions";
class LoginContainer extends Component {
constructor(state) {
super(state);
this.state = {
isAuthenticated: false,
isLoggingIn: false,
loginError: null,
}
}
componentWillReceiveProps(nextProps) {
if (this.state.isAuthenticated !== nextProps.isAuthenticated) {
if (nextProps.isAuthenticated) {
this.props.onLogin();
}
}
if (this.state.isLoggingIn !== nextProps.isLoggingIn) {
this.setState({isLoggingIn: nextProps.isLoggingIn})
}
if (this.state.loginError !== nextProps.loginError) {
this.setState({loginError: nextProps.loginError})
}
}
render() {
return <Login {...this.state} requestLogin={this.props.requestLogin}/>
}
}
export default connect(
(state) => ({
isAuthenticated: state.isAuthenticated,
isLoggingIn: state.isLoggingIn,
loginError: state.loginError,
}),
{requestLogin}
)(LoginContainer);