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';
|
2020-02-13 11:29:01 +01:00
|
|
|
import { IconLinks } from '@buffetjs/core';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2020-06-15 20:10:12 +08:00
|
|
|
import getTrad from '../../utils/getTrad';
|
2020-02-13 11:29:01 +01:00
|
|
|
import { PopUpWarning } from 'strapi-helper-plugin';
|
2020-01-08 12:21:47 +01:00
|
|
|
import en from '../../translations/en.json';
|
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
|
|
|
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 = () => {
|
2020-02-13 11:29:01 +01:00
|
|
|
let links = [
|
2017-11-06 18:15:53 +01:00
|
|
|
{
|
2020-02-13 11:29:01 +01:00
|
|
|
icon: <FontAwesomeIcon icon="pencil-alt" />,
|
2017-11-07 16:33:15 +01:00
|
|
|
onClick: this.handleClick,
|
2017-11-06 18:15:53 +01:00
|
|
|
},
|
|
|
|
{
|
2020-02-13 11:29:01 +01:00
|
|
|
icon: <FontAwesomeIcon icon="trash-alt" />,
|
|
|
|
onClick: e => {
|
|
|
|
e.stopPropagation();
|
2019-04-02 17:44:25 +02:00
|
|
|
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', ''))) {
|
2020-02-13 11:29:01 +01:00
|
|
|
links = [];
|
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', ''))) {
|
2020-02-13 11:29:01 +01:00
|
|
|
links = [
|
|
|
|
{
|
|
|
|
icon: <FontAwesomeIcon icon="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">
|
2020-02-13 11:29:01 +01:00
|
|
|
<IconLinks links={links} />
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Wrapper>
|
2017-11-06 18:15:53 +01:00
|
|
|
);
|
|
|
|
case 'providers':
|
2020-02-13 11:36:19 +01:00
|
|
|
links.pop(); // Remove the delete CTA
|
2019-11-26 16:24:53 +01:00
|
|
|
|
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-25 17:08:30 +01:00
|
|
|
<i
|
2020-04-26 18:55:03 +02:00
|
|
|
className={`fa${this.props.item.key !== undefined ? 'b' : ''} fa-${
|
|
|
|
this.props.item.icon
|
|
|
|
}`}
|
2019-11-25 17:08:30 +01:00
|
|
|
/>
|
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' }}>
|
2020-04-26 18:55:03 +02:00
|
|
|
{get(this.props.values, [get(this.props.item, 'name'), 'enabled']) ? (
|
2020-06-15 20:10:12 +08:00
|
|
|
<span style={{ color: '#5A9E06' }}>
|
|
|
|
<FormattedMessage id={getTrad('ListRow.enabled')} />
|
|
|
|
</span>
|
2019-09-13 15:17:24 +02:00
|
|
|
) : (
|
2020-06-15 20:10:12 +08:00
|
|
|
<span style={{ color: '#F64D0A' }}>
|
|
|
|
<FormattedMessage id={getTrad('ListRow.disabled')} />
|
|
|
|
</span>
|
2019-09-13 15:17:24 +02:00
|
|
|
)}
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-04-09 12:09:03 +02:00
|
|
|
<div className="col-md-2">
|
2020-02-13 11:29:01 +01:00
|
|
|
<IconLinks links={links} />
|
2017-11-06 18:15:53 +01:00
|
|
|
</div>
|
2019-09-13 15:17:24 +02:00
|
|
|
</Wrapper>
|
2017-11-06 18:15:53 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
case 'email-templates':
|
2020-02-13 11:36:19 +01:00
|
|
|
links.pop(); // Remove the delete CTA
|
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-25 17:08:30 +01:00
|
|
|
<i className={`fas 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] ? (
|
2020-05-14 02:20:28 +04:00
|
|
|
<FormattedMessage id={getTrad(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">
|
2020-02-13 11:29:01 +01:00
|
|
|
<IconLinks links={links} />
|
2017-11-06 18:15:53 +01:00
|
|
|
</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': {
|
2020-04-26 18:55: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;
|