2017-11-06 18:15:53 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* ListRow
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import cn from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-01-18 18:21:49 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-11-23 17:48:49 +01:00
|
|
|
import { get, includes } from 'lodash';
|
2017-11-07 16:33:15 +01:00
|
|
|
import { router } from 'app';
|
2017-11-06 18:15:53 +01:00
|
|
|
|
|
|
|
// Design
|
|
|
|
import IcoContainer from 'components/IcoContainer';
|
2017-11-06 18:25:40 +01:00
|
|
|
import PopUpWarning from 'components/PopUpWarning';
|
|
|
|
|
2018-01-18 18:21:49 +01:00
|
|
|
import en from 'translations/en.json';
|
2017-11-06 18:15:53 +01:00
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
|
|
class ListRow extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
2017-11-06 18:25:40 +01:00
|
|
|
state = { showModalDelete: false };
|
|
|
|
|
2017-12-04 15:03:53 +01:00
|
|
|
// Roles that can't be deleted && modified
|
2017-11-23 17:48:49 +01:00
|
|
|
// Don't delete this line
|
2017-11-27 17:50:51 +01:00
|
|
|
protectedRoleIDs = ['0'];
|
2017-11-23 17:48:49 +01:00
|
|
|
|
2017-12-04 15:03:53 +01:00
|
|
|
// Roles that can't be deleted;
|
|
|
|
undeletableIDs = ['1'];
|
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
generateContent = () => {
|
|
|
|
let icons = [
|
|
|
|
{
|
|
|
|
icoType: 'pencil',
|
2017-11-07 16:33:15 +01:00
|
|
|
onClick: this.handleClick,
|
2017-11-06 18:15:53 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icoType: 'trash',
|
2017-11-08 16:06:21 +01:00
|
|
|
onClick: () => { this.setState({ showModalDelete: true }); },
|
2017-11-06 18:15:53 +01:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
switch (this.props.settingType) {
|
|
|
|
case 'roles':
|
2018-01-19 13:52:43 +01:00
|
|
|
if (includes(this.protectedRoleIDs, get(this.props.item, 'id', '').toString())) {
|
2017-11-27 17:50:51 +01:00
|
|
|
icons = [];
|
2017-11-23 17:48:49 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 13:52:43 +01:00
|
|
|
if (includes(this.undeletableIDs, get(this.props.item, 'id', '').toString())) {
|
2017-12-04 15:03:53 +01:00
|
|
|
icons = [{ icoType: 'pencil', onClick: this.handleClick }];
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
return (
|
|
|
|
<div className={cn('row', styles.wrapper)}>
|
|
|
|
<div className="col-md-2">
|
|
|
|
<b>{this.props.item.name}</b>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-7">
|
|
|
|
{this.props.item.description}
|
|
|
|
</div>
|
|
|
|
<div className="col-md-1">
|
2017-11-30 16:34:43 +01:00
|
|
|
<strong>{this.props.item.nb_users || 0}</strong>
|
2017-11-06 18:15:53 +01:00
|
|
|
{this.props.item.nb_users > 1 ? (
|
|
|
|
'users'
|
|
|
|
) : (
|
|
|
|
'user'
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="col-md-2">
|
|
|
|
<IcoContainer icons={icons} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
case 'providers':
|
|
|
|
return (
|
|
|
|
<div className={cn('row', styles.wrapper)}>
|
|
|
|
<div className="col-md-4">
|
|
|
|
<div className={styles.flex}>
|
|
|
|
<div>
|
|
|
|
<i className={`fa fa-${this.props.item.ico}`} />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{this.props.item.name}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-11-14 10:31:18 +01:00
|
|
|
<div className="col-md-6" style={{ fontWeight: '500' }}>
|
2017-11-06 18:15:53 +01:00
|
|
|
{this.props.item.enabled ? (
|
|
|
|
<span style={{ color: '#5A9E06' }}>Enabled</span>
|
|
|
|
) : (
|
|
|
|
<span style={{ color: '#F64D0A' }}>Disabled</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="col-md-2">
|
|
|
|
<IcoContainer icons={icons} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
case 'email-templates':
|
|
|
|
icons = [
|
|
|
|
{
|
|
|
|
icoType: 'pencil',
|
2017-11-07 16:33:15 +01:00
|
|
|
onClick: this.handleClick,
|
2017-11-06 18:15:53 +01:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={cn('row', styles.wrapper)}>
|
|
|
|
<div className="col-md-4">
|
|
|
|
<div className={styles.flex}>
|
|
|
|
<div>
|
2018-01-18 18:21:49 +01:00
|
|
|
<i className={`fa fa-${this.props.item.icon}`} />
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
2018-01-18 18:21:49 +01:00
|
|
|
{this.props.item.display && en[this.props.item.display] ? (
|
|
|
|
<FormattedMessage id={`users-permissions.${this.props.item.display}`} />
|
|
|
|
): this.props.item.name}
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-8">
|
|
|
|
<IcoContainer icons={icons} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
handleClick = () => {
|
2018-01-18 18:21:49 +01:00
|
|
|
// TODO open modal and pass data
|
2017-11-07 16:33:15 +01:00
|
|
|
switch (this.props.settingType) {
|
2017-11-27 17:50:51 +01:00
|
|
|
case 'roles': {
|
|
|
|
if (!includes(this.protectedRoleIDs, get(this.props.item, 'id').toString())) {
|
|
|
|
return router.push(`${router.location.pathname}/edit/${this.props.item.id}`);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-11-07 16:33:15 +01:00
|
|
|
case 'providers':
|
|
|
|
case 'email-templates':
|
2018-01-19 13:34:55 +01:00
|
|
|
return this.context.setDataToEdit(this.props.item.name);
|
2017-11-07 16:33:15 +01:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 11:28:43 +01:00
|
|
|
handleDelete = () => {
|
|
|
|
this.props.deleteData(this.props.item, this.props.settingType);
|
|
|
|
this.setState({ showModalDelete: false });
|
|
|
|
}
|
2017-11-07 16:33:15 +01:00
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
render() {
|
|
|
|
return (
|
2017-11-07 16:33:15 +01:00
|
|
|
<li className={styles.li} onClick={this.handleClick}>
|
2017-11-06 18:15:53 +01:00
|
|
|
<div className={styles.container}>
|
|
|
|
{this.generateContent()}
|
|
|
|
</div>
|
2017-11-07 14:32:31 +01:00
|
|
|
<PopUpWarning
|
|
|
|
isOpen={this.state.showModalDelete}
|
|
|
|
onConfirm={this.handleDelete}
|
|
|
|
toggleModal={() => this.setState({ showModalDelete: false })}
|
|
|
|
/>
|
2017-11-06 18:15:53 +01:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:34:55 +01:00
|
|
|
ListRow.contextTypes = {
|
|
|
|
setDataToEdit: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
ListRow.defaultProps = {
|
|
|
|
item: {
|
|
|
|
name: 'Owner',
|
|
|
|
description: 'Rule them all. This role can\'t be deleted',
|
|
|
|
nb_users: 1,
|
2018-01-18 18:21:49 +01:00
|
|
|
icon: 'envelope',
|
2017-11-06 18:15:53 +01:00
|
|
|
},
|
|
|
|
settingType: 'roles',
|
2017-11-08 16:06:21 +01:00
|
|
|
};
|
2017-11-06 18:15:53 +01:00
|
|
|
|
2017-11-08 16:06:21 +01:00
|
|
|
ListRow.propTypes = {
|
2017-11-07 14:32:31 +01:00
|
|
|
deleteData: PropTypes.func.isRequired,
|
2017-11-06 18:15:53 +01:00
|
|
|
item: PropTypes.object,
|
|
|
|
settingType: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ListRow;
|