2017-09-21 17:08:00 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { appInit } from '../actions';
|
|
|
|
|
|
|
|
import AuthRoutes from './routes/AuthRoutes';
|
|
|
|
import PublicRoutes from './routes/PublicRoutes';
|
2017-11-07 16:28:02 +00:00
|
|
|
import Loading from '../presentation/Loading';
|
2017-09-21 17:08:00 +00:00
|
|
|
|
|
|
|
@connect(
|
|
|
|
state => ({
|
|
|
|
login: state.login,
|
|
|
|
app: state.app
|
|
|
|
}),
|
|
|
|
dispatch => bindActionCreators({
|
|
|
|
appInit
|
|
|
|
}, dispatch)
|
|
|
|
)
|
|
|
|
export default class Routes extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
login: PropTypes.object.isRequired,
|
|
|
|
app: PropTypes.object.isRequired,
|
|
|
|
appInit: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.props.appInit();
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
const { login, app } = this.props;
|
|
|
|
|
|
|
|
if (app.starting) {
|
2017-11-07 16:28:02 +00:00
|
|
|
return (<Loading />);
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 16:28:02 +00:00
|
|
|
if ((login.token && !login.failure && !login.isRegistering) || app.ready) {
|
2017-09-21 17:08:00 +00:00
|
|
|
return (<AuthRoutes />);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (<PublicRoutes />);
|
|
|
|
}
|
|
|
|
}
|