94 lines
2.6 KiB
JavaScript
Raw Normal View History

/*
*
* 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';
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';
import selectHome from './selectors';
import { configFetch } from './actions'
import styles from './styles.scss';
import config from './config.json';
export class Home extends React.Component { // eslint-disable-line react/prefer-stateless-function
componentDidMount() {
if (this.props.params.slug) {
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 16:55:59 +02:00
componentWillReceiveProps(nextProps) {
// 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) {
// 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
}
render() {
2017-07-17 19:19:54 +02:00
if (this.props.home.loading) {
return <div />;
}
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}} />
</div>
);
}
}
2017-07-18 12:39:03 +02:00
2017-07-17 18:40:11 +02:00
const mapStateToProps = createStructuredSelector({
home: selectHome(),
sections: makeSelectSections(),
})
function mapDispatchToProps(dispatch) {
2017-07-13 16:55:59 +02:00
return bindActionCreators(
{
configFetch,
},
dispatch
)
}
Home.propTypes = {
configFetch: React.PropTypes.func.isRequired,
params: React.PropTypes.object.isRequired,
2017-07-17 18:40:11 +02:00
sections: React.PropTypes.array,
};
export default connect(mapStateToProps, mapDispatchToProps)(Home);