2017-11-06 11:14:43 +01:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* HomePage
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
2017-11-06 17:03:20 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2017-11-06 11:14:43 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { createStructuredSelector } from 'reselect';
|
|
|
|
|
import { injectIntl } from 'react-intl';
|
|
|
|
|
import { bindActionCreators, compose } from 'redux';
|
2017-11-06 11:52:14 +01:00
|
|
|
import cn from 'classnames';
|
2017-11-06 12:27:53 +01:00
|
|
|
|
2017-11-06 11:52:14 +01:00
|
|
|
// Design
|
2017-11-07 19:58:08 +01:00
|
|
|
import EditForm from 'components/EditForm';
|
2017-11-06 12:27:53 +01:00
|
|
|
import HeaderNav from 'components/HeaderNav';
|
2017-11-06 17:03:20 +01:00
|
|
|
import List from 'components/List';
|
2017-11-06 11:52:14 +01:00
|
|
|
import PluginHeader from 'components/PluginHeader';
|
2017-11-06 11:14:43 +01:00
|
|
|
|
2017-11-06 12:27:53 +01:00
|
|
|
// Utils
|
2017-11-06 11:14:43 +01:00
|
|
|
import injectReducer from 'utils/injectReducer';
|
|
|
|
|
import injectSaga from 'utils/injectSaga';
|
|
|
|
|
|
|
|
|
|
// Selectors
|
|
|
|
|
import selectHomePage from './selectors';
|
|
|
|
|
|
|
|
|
|
// Styles
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
2017-11-06 17:03:20 +01:00
|
|
|
// Actions
|
|
|
|
|
import {
|
2017-11-07 14:32:31 +01:00
|
|
|
deleteData,
|
2017-11-06 17:03:20 +01:00
|
|
|
fetchData,
|
|
|
|
|
} from './actions';
|
|
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
import reducer from './reducer';
|
|
|
|
|
import saga from './saga';
|
|
|
|
|
|
|
|
|
|
export class HomePage extends React.Component {
|
2017-11-06 17:03:20 +01:00
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.fetchData(this.props.match.params.settingType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
|
if (prevProps.match.params.settingType !== this.props.match.params.settingType) {
|
|
|
|
|
this.props.fetchData(this.props.match.params.settingType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
onButtonClick = () => this.props.history.push(`${this.props.location.pathname}/create`);
|
|
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
render() {
|
2017-11-06 17:03:20 +01:00
|
|
|
const noButtonList = this.props.match.params.settingType === 'email-templates';
|
|
|
|
|
const component = this.props.match.params.settingType === 'advanced-settings' ?
|
2017-11-07 19:58:08 +01:00
|
|
|
<EditForm /> :
|
2017-11-06 17:03:20 +01:00
|
|
|
<List
|
|
|
|
|
data={this.props.data}
|
2017-11-07 14:32:31 +01:00
|
|
|
deleteActionSucceeded={this.props.deleteActionSucceeded}
|
|
|
|
|
deleteData={this.props.deleteData}
|
2017-11-07 16:33:15 +01:00
|
|
|
noButton={noButtonList}
|
|
|
|
|
onButtonClick={this.onButtonClick}
|
|
|
|
|
settingType={this.props.match.params.settingType}
|
2017-11-06 17:03:20 +01:00
|
|
|
/>;
|
2017-11-07 20:19:08 +01:00
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
return (
|
2017-11-06 11:52:14 +01:00
|
|
|
<div>
|
|
|
|
|
<div className={cn('container-fluid', styles.containerFluid)}>
|
|
|
|
|
<PluginHeader
|
|
|
|
|
title={{ id: 'users-permissions.HomePage.header.title' }}
|
|
|
|
|
description={{ id: 'users-permissions.HomePage.header.description' }}
|
|
|
|
|
actions={[]}
|
2017-11-06 12:27:53 +01:00
|
|
|
/>
|
|
|
|
|
<HeaderNav />
|
2017-11-06 17:03:20 +01:00
|
|
|
{component}
|
2017-11-06 11:52:14 +01:00
|
|
|
</div>
|
2017-11-06 11:14:43 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 17:03:20 +01:00
|
|
|
HomePage.defaultProps = {};
|
2017-11-06 11:14:43 +01:00
|
|
|
|
|
|
|
|
HomePage.propTypes = {
|
2017-11-06 17:03:20 +01:00
|
|
|
data: PropTypes.array.isRequired,
|
2017-11-07 14:32:31 +01:00
|
|
|
deleteActionSucceeded: PropTypes.bool.isRequired,
|
|
|
|
|
deleteData: PropTypes.func.isRequired,
|
2017-11-06 17:03:20 +01:00
|
|
|
fetchData: PropTypes.func.isRequired,
|
2017-11-06 11:14:43 +01:00
|
|
|
};
|
|
|
|
|
|
2017-11-06 17:03:20 +01:00
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
|
return bindActionCreators(
|
|
|
|
|
{
|
2017-11-07 14:32:31 +01:00
|
|
|
deleteData,
|
2017-11-06 17:03:20 +01:00
|
|
|
fetchData,
|
2017-11-06 11:14:43 +01:00
|
|
|
},
|
|
|
|
|
dispatch,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 17:03:20 +01:00
|
|
|
const mapStateToProps = selectHomePage();
|
2017-11-06 11:14:43 +01:00
|
|
|
|
|
|
|
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
|
|
const withReducer = injectReducer({ key: 'homePage', reducer });
|
|
|
|
|
const withSaga = injectSaga({ key: 'homePage', saga });
|
|
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
|
withReducer,
|
|
|
|
|
withSaga,
|
|
|
|
|
withConnect,
|
|
|
|
|
)(injectIntl(HomePage));
|