75 lines
2.0 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';
import { includes } from 'lodash';
import Helmet from 'react-helmet';
import selectHome from './selectors';
import { configFetch, environmentsFetch } 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 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) {
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
}
}
render() {
console.log(config);
return (
<div className={styles.home}>
2017-07-06 16:18:43 +02:00
<Helmet
title="Home"
meta={[
{ name: 'description', content: 'Description of Home' },
]}
/>
</div>
);
}
}
const mapStateToProps = selectHome();
function mapDispatchToProps(dispatch) {
2017-07-13 16:55:59 +02:00
return bindActionCreators(
{
configFetch,
environmentsFetch,
2017-07-13 16:55:59 +02:00
},
dispatch
)
}
export default connect(mapStateToProps, mapDispatchToProps)(Home);