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 { injectIntl } from 'react-intl';
|
|
|
|
|
import { bindActionCreators, compose } from 'redux';
|
2017-11-06 11:52:14 +01:00
|
|
|
import cn from 'classnames';
|
2017-11-09 14:33:26 +01:00
|
|
|
import { clone, includes, isEmpty, replace } from 'lodash';
|
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-08 12:22:03 +01:00
|
|
|
import PopUpForm from 'components/PopUpForm';
|
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,
|
2017-11-08 16:06:21 +01:00
|
|
|
onChange,
|
2017-11-06 17:03:20 +01:00
|
|
|
} from './actions';
|
|
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
import reducer from './reducer';
|
|
|
|
|
import saga from './saga';
|
|
|
|
|
|
2017-11-09 14:33:26 +01:00
|
|
|
const keyBoardShortCuts = [18, 78];
|
|
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
export class HomePage extends React.Component {
|
2017-11-09 14:33:26 +01:00
|
|
|
state = { mapKey: {} };
|
|
|
|
|
|
2017-11-06 17:03:20 +01:00
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.fetchData(this.props.match.params.settingType);
|
2017-11-09 14:33:26 +01:00
|
|
|
document.addEventListener('keydown', this.handleKeyBoardShortCut);
|
|
|
|
|
document.addEventListener('keyup', this.handleKeyBoardShortCut);
|
2017-11-06 17:03:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
|
if (prevProps.match.params.settingType !== this.props.match.params.settingType) {
|
|
|
|
|
this.props.fetchData(this.props.match.params.settingType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 14:33:26 +01:00
|
|
|
componentWillUnmount() {
|
|
|
|
|
document.removeEventListener('keydown', this.handleKeyBoardShortCut);
|
|
|
|
|
document.removeEventListener('keyup', this.handleKeyBoardShortCut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleKeyBoardShortCut = (e) => {
|
|
|
|
|
if (includes(keyBoardShortCuts, e.keyCode)) {
|
|
|
|
|
const mapKey = clone(this.state.mapKey);
|
|
|
|
|
mapKey[e.keyCode] = e.type === 'keydown';
|
|
|
|
|
this.setState({ mapKey });
|
|
|
|
|
|
|
|
|
|
// Check if user pressed option + n;
|
|
|
|
|
if (mapKey[18] && mapKey[78]) {
|
|
|
|
|
this.setState({ mapKey: {} });
|
|
|
|
|
this.handleButtonClick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 16:06:21 +01:00
|
|
|
handleButtonClick = () => {
|
2017-11-08 12:22:03 +01:00
|
|
|
if (this.props.match.params.settingType === 'roles') {
|
|
|
|
|
this.props.history.push(`${this.props.location.pathname}/create`);
|
2017-11-09 14:33:26 +01:00
|
|
|
} else if (this.props.match.params.settingType === 'providers') {
|
2017-11-08 12:22:03 +01:00
|
|
|
this.props.history.push(`${this.props.location.pathname}#add::${this.props.match.params.settingType}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-07 16:33:15 +01:00
|
|
|
|
2017-11-08 16:06:21 +01:00
|
|
|
pluginHeaderActions = [
|
|
|
|
|
{
|
|
|
|
|
label: 'users-permissions.EditPage.cancel',
|
|
|
|
|
kind: 'secondary',
|
|
|
|
|
onClick: () => console.log('cancel'),
|
|
|
|
|
type: 'button',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
kind: 'primary',
|
|
|
|
|
label: 'users-permissions.EditPage.submit',
|
|
|
|
|
onClick: () => console.log('submit'),
|
|
|
|
|
type: 'submit',
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
render() {
|
2017-11-08 16:06:21 +01:00
|
|
|
const headerActions = this.props.match.params.settingType === 'advanced-settings' && this.props.showButtons ?
|
|
|
|
|
this.pluginHeaderActions : [];
|
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-08 16:06:21 +01:00
|
|
|
<EditForm onChange={this.props.onChange} values={this.props.modifiedData} /> : (
|
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}
|
2017-11-08 16:06:21 +01:00
|
|
|
onButtonClick={this.handleButtonClick}
|
2017-11-07 16:33:15 +01:00
|
|
|
settingType={this.props.match.params.settingType}
|
2017-11-08 16:06:21 +01:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
const hashArray = replace(this.props.location.hash, '#', '').split('::');
|
2017-11-08 12:22:03 +01:00
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
return (
|
2017-11-06 11:52:14 +01:00
|
|
|
<div>
|
2017-11-08 16:06:21 +01:00
|
|
|
<form
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
console.log('submit');
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className={cn('container-fluid', styles.containerFluid)}>
|
|
|
|
|
<PluginHeader
|
|
|
|
|
title={{ id: 'users-permissions.HomePage.header.title' }}
|
|
|
|
|
description={{ id: 'users-permissions.HomePage.header.description' }}
|
|
|
|
|
actions={headerActions}
|
|
|
|
|
/>
|
|
|
|
|
<HeaderNav />
|
|
|
|
|
{component}
|
|
|
|
|
</div>
|
|
|
|
|
<PopUpForm
|
|
|
|
|
actionType={hashArray[0]}
|
|
|
|
|
isOpen={!isEmpty(this.props.location.hash)}
|
|
|
|
|
onChange={this.props.onChange}
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
console.log('submit popUp');
|
|
|
|
|
}}
|
|
|
|
|
settingType={hashArray[1]}
|
|
|
|
|
values={this.props.modifiedData}
|
2017-11-06 12:27:53 +01:00
|
|
|
/>
|
2017-11-08 16:06:21 +01:00
|
|
|
</form>
|
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-08 16:06:21 +01:00
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
|
location: PropTypes.object.isRequired,
|
|
|
|
|
match: PropTypes.object.isRequired,
|
|
|
|
|
modifiedData: PropTypes.object.isRequired,
|
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
|
showButtons: PropTypes.bool.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-08 16:06:21 +01:00
|
|
|
onChange,
|
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));
|