2017-07-06 14:03:20 +02:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Home
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
2017-07-13 16:55:59 +02:00
|
|
|
import { bindActionCreators } from 'redux';
|
2017-07-17 18:40:11 +02:00
|
|
|
import { createStructuredSelector } from 'reselect';
|
2017-07-18 12:39:03 +02:00
|
|
|
import { map } from 'lodash';
|
2017-07-06 14:03:20 +02:00
|
|
|
import Helmet from 'react-helmet';
|
2017-07-17 18:40:11 +02:00
|
|
|
import { router } from 'app';
|
2017-07-18 12:39:03 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-07-17 19:19:54 +02:00
|
|
|
// design
|
|
|
|
|
import ContentHeader from 'components/ContentHeader';
|
|
|
|
|
|
2017-07-17 18:40:11 +02:00
|
|
|
import { makeSelectSections } from 'containers/App/selectors';
|
2017-07-06 14:03:20 +02:00
|
|
|
import selectHome from './selectors';
|
2017-07-17 17:44:19 +02:00
|
|
|
import { configFetch } from './actions'
|
2017-07-06 14:03:20 +02:00
|
|
|
import styles from './styles.scss';
|
2017-07-17 18:53:42 +02:00
|
|
|
import config from './config.json';
|
2017-07-06 14:03:20 +02:00
|
|
|
|
|
|
|
|
export class Home extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
2017-07-17 12:36:04 +02:00
|
|
|
|
2017-07-13 18:50:51 +02:00
|
|
|
componentDidMount() {
|
|
|
|
|
if (this.props.params.slug) {
|
2017-07-17 17:44:19 +02:00
|
|
|
const apiUrl = this.props.params.env ? `${this.props.params.slug}/${this.props.params.env}` : this.props.params.slug;
|
|
|
|
|
this.props.configFetch(apiUrl);
|
2017-07-17 18:40:11 +02:00
|
|
|
} else {
|
|
|
|
|
router.push(`/plugins/settings-manager/${this.props.sections[0].items[0].slug}`);
|
2017-07-13 18:50:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-17 12:36:04 +02:00
|
|
|
|
2017-07-13 16:55:59 +02:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-07-17 12:36:04 +02:00
|
|
|
// check if params slug updated
|
2017-07-17 18:40:11 +02:00
|
|
|
if (this.props.params.slug !== nextProps.params.slug) {
|
|
|
|
|
if (nextProps.params.slug) {
|
|
|
|
|
// get data from api if params slug updated
|
|
|
|
|
const apiUrl = nextProps.params.env ? `${nextProps.params.slug}/${nextProps.params.env}` : nextProps.params.slug;
|
|
|
|
|
this.props.configFetch(apiUrl);
|
|
|
|
|
} else {
|
|
|
|
|
// redirect user if no params slug provided
|
|
|
|
|
router.push(`/plugins/settings-manager/${this.props.sections[0].items[0].slug}`);
|
|
|
|
|
}
|
|
|
|
|
} else if (this.props.params.env !== nextProps.params.env && nextProps.params.env) {
|
2017-07-17 12:36:04 +02:00
|
|
|
// get data if params env updated
|
|
|
|
|
this.props.configFetch(`${this.props.params.slug}/${nextProps.params.env}`);
|
2017-07-13 16:55:59 +02:00
|
|
|
}
|
2017-07-17 18:40:11 +02:00
|
|
|
|
2017-07-13 16:55:59 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-06 14:03:20 +02:00
|
|
|
render() {
|
2017-07-17 19:19:54 +02:00
|
|
|
if (this.props.home.loading) {
|
|
|
|
|
return <div />;
|
|
|
|
|
}
|
2017-07-06 14:03:20 +02:00
|
|
|
return (
|
|
|
|
|
<div className={styles.home}>
|
2017-07-06 16:18:43 +02:00
|
|
|
<Helmet
|
|
|
|
|
title="Home"
|
|
|
|
|
meta={[
|
|
|
|
|
{ name: 'description', content: 'Description of Home' },
|
|
|
|
|
]}
|
|
|
|
|
/>
|
2017-07-18 12:39:03 +02:00
|
|
|
<FormattedMessage {...{id: this.props.home.configsDisplay.name}} />
|
2017-07-06 14:03:20 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 12:39:03 +02:00
|
|
|
|
2017-07-17 18:40:11 +02:00
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
|
|
|
home: selectHome(),
|
|
|
|
|
sections: makeSelectSections(),
|
|
|
|
|
})
|
2017-07-06 14:03:20 +02:00
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
2017-07-13 16:55:59 +02:00
|
|
|
return bindActionCreators(
|
|
|
|
|
{
|
|
|
|
|
configFetch,
|
|
|
|
|
},
|
|
|
|
|
dispatch
|
|
|
|
|
)
|
2017-07-06 14:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-17 12:36:04 +02:00
|
|
|
Home.propTypes = {
|
|
|
|
|
configFetch: React.PropTypes.func.isRequired,
|
|
|
|
|
params: React.PropTypes.object.isRequired,
|
2017-07-17 18:40:11 +02:00
|
|
|
sections: React.PropTypes.array,
|
2017-07-17 12:36:04 +02:00
|
|
|
};
|
|
|
|
|
|
2017-07-06 14:03:20 +02:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Home);
|