2017-11-07 14:32:31 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* EditPage
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2017-11-07 16:33:15 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2017-11-07 14:32:31 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createStructuredSelector } from 'reselect';
|
|
|
|
import { bindActionCreators, compose } from 'redux';
|
2017-11-07 16:33:15 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-11-07 18:16:42 +01:00
|
|
|
import { get, size } from 'lodash';
|
2017-11-07 16:33:15 +01:00
|
|
|
import cn from 'classnames';
|
|
|
|
|
|
|
|
// Design
|
|
|
|
import BackHeader from 'components/BackHeader';
|
|
|
|
import Input from 'components/Input';
|
|
|
|
import InputSearch from 'components/InputSearch';
|
|
|
|
import PluginHeader from 'components/PluginHeader';
|
2017-11-07 14:32:31 +01:00
|
|
|
|
|
|
|
import injectSaga from 'utils/injectSaga';
|
|
|
|
import injectReducer from 'utils/injectReducer';
|
2017-11-07 16:33:15 +01:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
import {
|
2017-11-07 18:16:42 +01:00
|
|
|
addUser,
|
2017-11-15 15:11:10 +01:00
|
|
|
getPermissions,
|
|
|
|
getRole,
|
2017-11-07 16:33:15 +01:00
|
|
|
onCancel,
|
|
|
|
onChangeInput,
|
2017-11-07 18:16:42 +01:00
|
|
|
onClickDelete,
|
2017-11-15 14:00:51 +01:00
|
|
|
setForm,
|
2017-11-07 16:33:15 +01:00
|
|
|
} from './actions';
|
|
|
|
|
|
|
|
// Selectors
|
2017-11-07 14:32:31 +01:00
|
|
|
import makeSelectEditPage from './selectors';
|
2017-11-07 16:33:15 +01:00
|
|
|
|
2017-11-07 14:32:31 +01:00
|
|
|
import reducer from './reducer';
|
|
|
|
import saga from './saga';
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2017-11-07 14:32:31 +01:00
|
|
|
export class EditPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
2017-11-15 14:00:51 +01:00
|
|
|
componentDidMount() {
|
|
|
|
if (this.props.match.params.actionType === 'create') {
|
|
|
|
this.props.setForm();
|
2017-11-15 15:11:10 +01:00
|
|
|
this.props.getPermissions();
|
|
|
|
} else {
|
|
|
|
this.props.getRole(this.props.match.params.id);
|
2017-11-15 14:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
pluginHeaderActions = [
|
|
|
|
{
|
|
|
|
label: 'users-permissions.EditPage.cancel',
|
|
|
|
kind: 'secondary',
|
|
|
|
onClick: this.props.onCancel,
|
|
|
|
type: 'button',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
kind: 'primary',
|
|
|
|
label: 'users-permissions.EditPage.submit',
|
|
|
|
onClick: () => console.log('submit'),
|
|
|
|
type: 'submit',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2017-11-07 14:32:31 +01:00
|
|
|
render() {
|
2017-11-15 14:00:51 +01:00
|
|
|
const pluginHeaderTitle = this.props.match.params.actionType === 'create' ?
|
2017-11-07 16:33:15 +01:00
|
|
|
'users-permissions.EditPage.header.title.create'
|
|
|
|
: 'users-permissions.EditPage.header.title';
|
2017-11-15 14:00:51 +01:00
|
|
|
const pluginHeaderDescription = this.props.match.params.actionType === 'create' ?
|
2017-11-07 16:33:15 +01:00
|
|
|
'users-permissions.EditPage.header.description.create'
|
|
|
|
: 'users-permissions.EditPage.header.description';
|
|
|
|
const pluginHeaderActions = this.props.editPage.showButtons ? this.pluginHeaderActions : [];
|
2017-11-15 15:11:10 +01:00
|
|
|
|
2017-11-07 14:32:31 +01:00
|
|
|
return (
|
|
|
|
<div>
|
2017-11-07 16:33:15 +01:00
|
|
|
<BackHeader onClick={() => this.props.history.goBack()} />
|
|
|
|
<div className={cn('container-fluid', styles.containerFluid)}>
|
|
|
|
<PluginHeader
|
|
|
|
title={{
|
|
|
|
id: pluginHeaderTitle,
|
|
|
|
values: {
|
2017-11-15 15:11:10 +01:00
|
|
|
name: get(this.props.editPage.initialData, 'name'),
|
2017-11-07 16:33:15 +01:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
description={{
|
|
|
|
id: pluginHeaderDescription,
|
|
|
|
values: {
|
2017-11-15 15:11:10 +01:00
|
|
|
description: get(this.props.editPage.initialData, 'description') || '',
|
2017-11-07 16:33:15 +01:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
actions={pluginHeaderActions}
|
|
|
|
/>
|
2017-11-15 15:11:10 +01:00
|
|
|
<div className={cn("row", styles.container)}>
|
2017-11-07 16:33:15 +01:00
|
|
|
<div className="col-md-12">
|
|
|
|
<div className={styles.main_wrapper}>
|
|
|
|
<div className={styles.titleContainer}>
|
|
|
|
<FormattedMessage id="users-permissions.EditPage.form.roles" />
|
|
|
|
</div>
|
|
|
|
<form className={styles.form}>
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-6">
|
|
|
|
<div className="row">
|
|
|
|
<Input
|
2017-11-14 16:42:08 +01:00
|
|
|
autoFocus
|
2017-11-07 16:33:15 +01:00
|
|
|
customBootstrapClass="col-md-12"
|
|
|
|
label="users-permissions.EditPage.form.roles.label.name"
|
|
|
|
name="name"
|
|
|
|
onChange={this.props.onChangeInput}
|
|
|
|
type="text"
|
|
|
|
validations={{ required: true }}
|
|
|
|
value={get(this.props.editPage, ['modifiedData', 'name'])}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="row">
|
|
|
|
<Input
|
|
|
|
customBootstrapClass="col-md-12"
|
|
|
|
label="users-permissions.EditPage.form.roles.label.description"
|
|
|
|
name="description"
|
|
|
|
onChange={this.props.onChangeInput}
|
|
|
|
type="textarea"
|
|
|
|
validations={{ required: true }}
|
|
|
|
value={get(this.props.editPage, ['modifiedData', 'description'])}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<InputSearch
|
2017-11-07 18:16:42 +01:00
|
|
|
addUser={this.props.addUser}
|
|
|
|
didDeleteUser={this.props.editPage.didDeleteUser}
|
2017-11-15 14:00:51 +01:00
|
|
|
didGetUsers={this.props.editPage.didGetUsers}
|
2017-11-07 16:33:15 +01:00
|
|
|
label="users-permissions.EditPage.form.roles.label.users"
|
2017-11-07 18:16:42 +01:00
|
|
|
labelValues={{ number: size(get(this.props.editPage, ['modifiedData', 'users'])) }}
|
2017-11-07 16:33:15 +01:00
|
|
|
type="text"
|
|
|
|
validations={{ required: true }}
|
2017-11-07 18:16:42 +01:00
|
|
|
values={get(this.props.editPage, ['modifiedData', 'users'])}
|
2017-11-07 16:33:15 +01:00
|
|
|
name="users"
|
2017-11-07 18:16:42 +01:00
|
|
|
onClickDelete={this.props.onClickDelete}
|
2017-11-07 16:33:15 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-11-07 14:32:31 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditPage.propTypes = {
|
2017-11-07 18:16:42 +01:00
|
|
|
addUser: PropTypes.func.isRequired,
|
2017-11-08 16:06:21 +01:00
|
|
|
editPage: PropTypes.object.isRequired,
|
2017-11-15 15:11:10 +01:00
|
|
|
getPermissions: PropTypes.func.isRequired,
|
|
|
|
getRole: PropTypes.func.isRequired,
|
2017-11-07 16:33:15 +01:00
|
|
|
history: PropTypes.object.isRequired,
|
2017-11-08 16:06:21 +01:00
|
|
|
match: PropTypes.object.isRequired,
|
2017-11-07 16:33:15 +01:00
|
|
|
onCancel: PropTypes.func.isRequired,
|
|
|
|
onChangeInput: PropTypes.func.isRequired,
|
2017-11-07 18:16:42 +01:00
|
|
|
onClickDelete: PropTypes.func.isRequired,
|
2017-11-15 14:00:51 +01:00
|
|
|
setForm: PropTypes.func.isRequired,
|
2017-11-07 14:32:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
2017-11-07 16:33:15 +01:00
|
|
|
editPage: makeSelectEditPage(),
|
2017-11-07 14:32:31 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(
|
2017-11-07 16:33:15 +01:00
|
|
|
{
|
2017-11-07 18:16:42 +01:00
|
|
|
addUser,
|
2017-11-15 15:11:10 +01:00
|
|
|
getPermissions,
|
|
|
|
getRole,
|
2017-11-07 16:33:15 +01:00
|
|
|
onCancel,
|
|
|
|
onChangeInput,
|
2017-11-07 18:16:42 +01:00
|
|
|
onClickDelete,
|
2017-11-15 14:00:51 +01:00
|
|
|
setForm,
|
2017-11-07 16:33:15 +01:00
|
|
|
},
|
|
|
|
dispatch,
|
2017-11-07 14:32:31 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
/* Remove this line if the container doesn't have a route and
|
|
|
|
* check the documentation to see how to create the container's store
|
|
|
|
*/
|
|
|
|
const withReducer = injectReducer({ key: 'editPage', reducer });
|
|
|
|
|
|
|
|
/* Remove the line below the container doesn't have a route and
|
|
|
|
* check the documentation to see how to create the container's store
|
|
|
|
*/
|
|
|
|
const withSaga = injectSaga({ key: 'editPage', saga });
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withReducer,
|
|
|
|
withSaga,
|
|
|
|
withConnect,
|
|
|
|
)(EditPage);
|