/*
*
* Home
*
*/
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { createStructuredSelector } from 'reselect';
import { findKey, includes, get, toNumber, isObject, find } from 'lodash';
import { FormattedMessage } from 'react-intl';
import Helmet from 'react-helmet';
import { router } from 'app';
// design
import ContentHeader from 'components/ContentHeader';
import EditForm from 'components/EditForm';
import HeaderNav from 'components/HeaderNav';
import List from 'components/List';
import { makeSelectSections, makeSelectEnvironments } from 'containers/App/selectors';
import selectHome from './selectors';
import { configFetch, changeInput, cancelChanges, submitChanges, languagesFetch } 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
constructor(props) {
super(props);
this.customComponents = config.customComponents;
this.components = {
editForm: EditForm,
list: List,
defaultComponent: HeaderNav, // TODO change to default
};
}
componentDidMount() {
if (this.props.params.slug) {
if (this.props.params.slug !== 'languages') {
const apiUrl = this.props.params.env ? `${this.props.params.slug}/${this.props.params.env}` : this.props.params.slug;
this.props.configFetch(apiUrl);
} else {
this.props.languagesFetch();
}
} else {
router.push(`/plugins/settings-manager/${get(this.props.menuSections, ['0', 'items', '0', 'slug'])}`);
}
}
componentWillReceiveProps(nextProps) {
// check if params slug updated
if (this.props.params.slug !== nextProps.params.slug && nextProps.params.slug) {
if (nextProps.params.slug) {
// get data from api if params slug updated
if (nextProps.params.slug !== 'languages') {
const apiUrl = nextProps.params.env ? `${nextProps.params.slug}/${nextProps.params.env}` : nextProps.params.slug;
this.props.configFetch(apiUrl);
} else {
this.props.languagesFetch();
}
} else {
// redirect user if no params slug provided
router.push(`/plugins/settings-manager/${get(this.props.menuSections, ['0', 'items', '0', 'slug'])}`);
}
} else if (this.props.params.env !== nextProps.params.env && nextProps.params.env && this.props.params.env) {
// get data if params env updated
this.props.configFetch(`${this.props.params.slug}/${nextProps.params.env}`);
}
}
handleChange = ({ target }) => {
const value = target.type === 'number' ? toNumber(target.value) : target.value;
this.props.changeInput(target.name, value);
}
handleCancel = () => {
this.props.cancelChanges();
}
handleSubmit = () => {
this.props.submitChanges();
}
addLanguage = () => {
console.log('fuck');
}
// custom Row rendering for the component List with params slug === languages
renderRowLanguage = (props, key) => {
// custom style
const rowStyle = {
defaultSpanStyle: {
color: '#49515A',
fontStyle: 'italic',
},
normalSpanStyle: {
color: '#1C5DE7',
},
tdNameStyle: {
color: '#333740',
},
tdLangDisplayStyle: {
color: '#333740',
fontWeight: '600',
},
};
const deleteIcon = props.active ? '' : ;
const languageLabel = props.active ?