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-13 18:50:51 +02:00
|
|
|
import { includes } from 'lodash';
|
2017-07-06 14:03:20 +02:00
|
|
|
import Helmet from 'react-helmet';
|
|
|
|
|
import selectHome from './selectors';
|
2017-07-13 18:50:51 +02:00
|
|
|
import { configFetch, environmentsFetch } from './actions'
|
2017-07-06 14:03:20 +02:00
|
|
|
import styles from './styles.scss';
|
2017-07-13 18:50:51 +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-13 18:50:51 +02:00
|
|
|
componentDidMount() {
|
|
|
|
|
if (this.props.params.slug) {
|
|
|
|
|
const isEnvironemntsRequired = includes(config.environmentsRequired, this.props.params.slug);
|
|
|
|
|
// TODO handle specific url for environments
|
|
|
|
|
if (!isEnvironemntsRequired) {
|
|
|
|
|
this.props.configFetch(this.props.params.slug);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.environmentsFetch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 16:55:59 +02:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-07-13 18:50:51 +02:00
|
|
|
if (this.props.params.slug !== nextProps.params.slug && nextProps.params.slug) {
|
|
|
|
|
// TODO add condition to check if environments has already been fetched
|
|
|
|
|
const isEnvironemntsRequired = includes(config.environmentsRequired, nextProps.params.slug);
|
|
|
|
|
|
|
|
|
|
if (!isEnvironemntsRequired) {
|
|
|
|
|
this.props.configFetch(nextProps.params.slug);
|
|
|
|
|
} else { // TODO change to else if (isEmpty(this.props.environments))
|
|
|
|
|
this.props.environmentsFetch();
|
|
|
|
|
} // else { ... }
|
|
|
|
|
|
|
|
|
|
} else if (this.props.params.env !== nextProps.params.env) {
|
|
|
|
|
// TODO handle environments
|
|
|
|
|
this.props.configFetch(`${nextProps.params.slug}/${nextProps.params.env}`);
|
2017-07-13 16:55:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-06 14:03:20 +02:00
|
|
|
render() {
|
2017-07-13 18:50:51 +02:00
|
|
|
console.log(config);
|
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-06 14:03:20 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = selectHome();
|
|
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
2017-07-13 16:55:59 +02:00
|
|
|
return bindActionCreators(
|
|
|
|
|
{
|
|
|
|
|
configFetch,
|
2017-07-13 18:50:51 +02:00
|
|
|
environmentsFetch,
|
2017-07-13 16:55:59 +02:00
|
|
|
},
|
|
|
|
|
dispatch
|
|
|
|
|
)
|
2017-07-06 14:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Home);
|