2017-11-06 18:15:53 +01:00
|
|
|
/**
|
2019-04-02 17:44:25 +02:00
|
|
|
*
|
|
|
|
* ListRow
|
|
|
|
*
|
|
|
|
*/
|
2017-11-06 18:15:53 +01:00
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-01-18 18:21:49 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2018-01-26 17:31:52 +01:00
|
|
|
import { capitalize, get, includes } from 'lodash';
|
2017-11-06 18:15:53 +01:00
|
|
|
|
2019-04-16 16:55:53 +02:00
|
|
|
import { IcoContainer, PopUpWarning } from 'strapi-helper-plugin';
|
2019-10-03 11:48:24 +02:00
|
|
|
import { HomePageContext } from '../../contexts/HomePage';
|
2019-09-18 17:39:54 +02:00
|
|
|
import { Container, Flex, Row, Wrapper } from './Components';
|
2017-11-06 18:25:40 +01:00
|
|
|
|
2019-04-02 17:44:25 +02:00
|
|
|
import en from '../../translations/en.json';
|
2019-09-13 15:17:24 +02:00
|
|
|
|
2019-04-02 17:44:25 +02:00
|
|
|
class ListRow extends React.Component {
|
|
|
|
// eslint-disable-line react/prefer-stateless-function
|
2017-11-06 18:25:40 +01:00
|
|
|
state = { showModalDelete: false };
|
|
|
|
|
2019-10-03 11:48:24 +02:00
|
|
|
static contextType = HomePageContext;
|
|
|
|
|
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
|
2019-04-09 12:09:03 +02:00
|
|
|
protectedRoleIDs = [];
|
2017-11-23 17:48:49 +01:00
|
|
|
|
2017-12-04 15:03:53 +01:00
|
|
|
// Roles that can't be deleted;
|
2018-03-14 16:56:12 +01:00
|
|
|
undeletableIDs = ['public', 'authenticated'];
|
2017-12-04 15:03:53 +01:00
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
generateContent = () => {
|
|
|
|
let icons = [
|
|
|
|
{
|
2019-11-19 16:17:15 +01:00
|
|
|
icoType: 'pencil-alt',
|
2017-11-07 16:33:15 +01:00
|
|
|
onClick: this.handleClick,
|
2017-11-06 18:15:53 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-25 15:56:44 +01:00
|
|
|
icoType: 'trash-alt',
|
2019-04-02 17:44:25 +02:00
|
|
|
onClick: () => {
|
|
|
|
this.setState({ showModalDelete: true });
|
|
|
|
},
|
2017-11-06 18:15:53 +01:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
switch (this.props.settingType) {
|
|
|
|
case 'roles':
|
2018-01-24 13:51:22 +01:00
|
|
|
if (includes(this.protectedRoleIDs, get(this.props.item, 'type', ''))) {
|
2017-11-27 17:50:51 +01:00
|
|
|
icons = [];
|
2017-11-23 17:48:49 +01:00
|
|
|
}
|
|
|
|
|
2018-01-24 13:51:22 +01:00
|
|
|
if (includes(this.undeletableIDs, get(this.props.item, 'type', ''))) {
|
2019-11-19 16:17:15 +01:00
|
|
|
icons = [{ icoType: 'pencil-alt', onClick: this.handleClick }];
|
2017-12-04 15:03:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
return (
|
2019-09-13 15:17:24 +02:00
|
|
|
<Wrapper className="row" style={{ paddingLeft: '20px' }}>
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-2">
|
2017-11-06 18:15:53 +01:00
|
|
|
<b>{this.props.item.name}</b>
|
|
|
|
</div>
|
2019-04-09 12:09:03 +02:00
|
|
|
<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>
|
2019-04-02 17:44:25 +02:00
|
|
|
{this.props.item.nb_users > 1 ? 'users' : 'user'}
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-2">
|
2017-11-06 18:15:53 +01:00
|
|
|
<IcoContainer icons={icons} />
|
|
|
|
</div>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Wrapper>
|
2017-11-06 18:15:53 +01:00
|
|
|
);
|
|
|
|
case 'providers':
|
2018-01-25 13:59:05 +01:00
|
|
|
icons.pop(); // Remove the icon-trash
|
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
return (
|
2019-09-13 15:17:24 +02:00
|
|
|
<Wrapper className="row">
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-4">
|
2019-09-13 15:17:24 +02:00
|
|
|
<Flex>
|
2017-11-06 18:15:53 +01:00
|
|
|
<div>
|
2019-11-19 16:17:15 +01:00
|
|
|
{/* <i className={`fa fa-${this.props.item.icon}`} /> */}
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-04-02 17:44:25 +02:00
|
|
|
<div>{capitalize(this.props.item.name)}</div>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Flex>
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-6" style={{ fontWeight: '500' }}>
|
|
|
|
{get(this.props.values, [
|
|
|
|
get(this.props.item, 'name'),
|
|
|
|
'enabled',
|
|
|
|
]) ? (
|
2019-09-13 15:17:24 +02:00
|
|
|
<span style={{ color: '#5A9E06' }}>Enabled</span>
|
|
|
|
) : (
|
|
|
|
<span style={{ color: '#F64D0A' }}>Disabled</span>
|
|
|
|
)}
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-2">
|
2017-11-06 18:15:53 +01:00
|
|
|
<IcoContainer icons={icons} />
|
|
|
|
</div>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Wrapper>
|
2017-11-06 18:15:53 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
case 'email-templates':
|
2018-01-25 13:59:05 +01:00
|
|
|
icons.pop();
|
2017-11-06 18:15:53 +01:00
|
|
|
|
|
|
|
return (
|
2019-09-13 15:17:24 +02:00
|
|
|
<Wrapper className="row">
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-4">
|
2019-09-13 15:17:24 +02:00
|
|
|
<Flex>
|
2017-11-06 18:15:53 +01:00
|
|
|
<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] ? (
|
2019-04-09 12:09:03 +02:00
|
|
|
<FormattedMessage
|
|
|
|
id={`users-permissions.${this.props.item.display}`}
|
|
|
|
/>
|
2019-04-02 17:44:25 +02:00
|
|
|
) : (
|
|
|
|
this.props.item.name
|
|
|
|
)}
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Flex>
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-8">
|
2017-11-06 18:15:53 +01:00
|
|
|
<IcoContainer icons={icons} />
|
|
|
|
</div>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Wrapper>
|
2017-11-06 18:15:53 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
2019-04-02 17:44:25 +02:00
|
|
|
};
|
2017-11-06 18:15:53 +01:00
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
handleClick = () => {
|
2019-04-02 17:44:25 +02:00
|
|
|
const { pathname, push } = this.context;
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
switch (this.props.settingType) {
|
2017-11-27 17:50:51 +01:00
|
|
|
case 'roles': {
|
2019-04-09 12:09:03 +02:00
|
|
|
if (
|
|
|
|
!includes(this.protectedRoleIDs, get(this.props.item, 'type', ''))
|
|
|
|
) {
|
2019-04-02 17:44:25 +02:00
|
|
|
return push(`${pathname}/edit/${this.props.item.id}`);
|
2017-11-27 17:50:51 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-11-07 16:33:15 +01:00
|
|
|
case 'providers':
|
2019-02-21 16:48:59 +01:00
|
|
|
this.context.emitEvent('willEditAuthenticationProvider');
|
2019-04-02 17:44:25 +02:00
|
|
|
|
2019-02-21 16:48:59 +01:00
|
|
|
return this.context.setDataToEdit(this.props.item.name);
|
2017-11-07 16:33:15 +01:00
|
|
|
case 'email-templates':
|
2019-02-21 16:48:59 +01:00
|
|
|
this.context.emitEvent('willEditEmailTemplates');
|
2019-04-02 17:44:25 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2019-04-02 17:44:25 +02:00
|
|
|
};
|
2017-11-07 16:33:15 +01:00
|
|
|
|
2018-01-15 11:28:43 +01:00
|
|
|
handleDelete = () => {
|
|
|
|
this.props.deleteData(this.props.item, this.props.settingType);
|
|
|
|
this.setState({ showModalDelete: false });
|
2019-04-02 17:44:25 +02:00
|
|
|
};
|
2017-11-07 16:33:15 +01:00
|
|
|
|
2017-11-06 18:15:53 +01:00
|
|
|
render() {
|
|
|
|
return (
|
2019-09-13 15:17:24 +02:00
|
|
|
<Row onClick={this.handleClick}>
|
|
|
|
<Container>{this.generateContent()}</Container>
|
2017-11-07 14:32:31 +01:00
|
|
|
<PopUpWarning
|
|
|
|
isOpen={this.state.showModalDelete}
|
|
|
|
onConfirm={this.handleDelete}
|
|
|
|
toggleModal={() => this.setState({ showModalDelete: false })}
|
|
|
|
/>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Row>
|
2017-11-06 18:15:53 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ListRow.defaultProps = {
|
|
|
|
item: {
|
|
|
|
name: 'Owner',
|
2019-09-13 15:17:24 +02:00
|
|
|
description: "Rule them all. This role can't be deleted",
|
2017-11-06 18:15:53 +01:00
|
|
|
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,
|
2018-01-22 11:00:41 +01:00
|
|
|
values: PropTypes.object.isRequired,
|
2017-11-06 18:15:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ListRow;
|