2016-09-07 20:07:45 +00:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-09-19 23:43:35 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { noop } from 'lodash';
|
2016-11-03 19:40:54 +00:00
|
|
|
import classnames from 'classnames';
|
2016-10-19 20:22:18 +00:00
|
|
|
|
2016-12-29 20:27:43 +00:00
|
|
|
import { authToken } from 'utilities/local';
|
|
|
|
|
import { fetchCurrentUser } from 'redux/nodes/auth/actions';
|
|
|
|
|
import { getConfig } from 'redux/nodes/app/actions';
|
|
|
|
|
import userInterface from 'interfaces/user';
|
2016-09-07 20:07:45 +00:00
|
|
|
|
|
|
|
|
export class App extends Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
children: PropTypes.element,
|
2016-09-19 23:43:35 +00:00
|
|
|
dispatch: PropTypes.func,
|
2016-09-23 21:20:02 +00:00
|
|
|
showBackgroundImage: PropTypes.bool,
|
2016-10-21 23:13:41 +00:00
|
|
|
user: userInterface,
|
2016-09-07 20:07:45 +00:00
|
|
|
};
|
|
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
static defaultProps = {
|
|
|
|
|
dispatch: noop,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
|
const { dispatch, user } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!user && !!authToken()) {
|
2016-10-04 20:51:30 +00:00
|
|
|
dispatch(fetchCurrentUser())
|
2016-10-19 20:22:18 +00:00
|
|
|
.catch(() => {
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2016-09-19 23:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-19 20:22:18 +00:00
|
|
|
if (user) {
|
|
|
|
|
dispatch(getConfig());
|
|
|
|
|
}
|
2016-10-05 23:43:37 +00:00
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 23:43:37 +00:00
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
|
const { dispatch, user } = nextProps;
|
|
|
|
|
|
2016-11-03 01:32:05 +00:00
|
|
|
if (user && this.props.user !== user) {
|
2016-10-19 20:22:18 +00:00
|
|
|
dispatch(getConfig());
|
|
|
|
|
}
|
2016-10-05 23:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-07 20:07:45 +00:00
|
|
|
render () {
|
2017-01-05 18:08:19 +00:00
|
|
|
const { children, showBackgroundImage } = this.props;
|
2016-09-07 20:07:45 +00:00
|
|
|
|
2016-11-03 19:40:54 +00:00
|
|
|
const wrapperStyles = classnames(
|
|
|
|
|
'wrapper',
|
|
|
|
|
{ 'wrapper--background': showBackgroundImage }
|
|
|
|
|
);
|
|
|
|
|
|
2016-09-07 20:07:45 +00:00
|
|
|
return (
|
2016-11-03 19:40:54 +00:00
|
|
|
<div className={wrapperStyles}>
|
2016-09-13 19:50:37 +00:00
|
|
|
{children}
|
2016-10-03 17:54:22 +00:00
|
|
|
</div>
|
2016-09-07 20:07:45 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
const mapStateToProps = (state) => {
|
2017-01-05 18:08:19 +00:00
|
|
|
const { app, auth } = state;
|
2016-12-29 20:27:43 +00:00
|
|
|
const { showBackgroundImage } = app;
|
|
|
|
|
const { user } = auth;
|
2016-09-19 23:43:35 +00:00
|
|
|
|
2016-09-23 21:20:02 +00:00
|
|
|
return {
|
|
|
|
|
showBackgroundImage,
|
|
|
|
|
user,
|
|
|
|
|
};
|
2016-09-19 23:43:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(App);
|