2021-02-04 19:15:23 +01:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import CheckBox from '../../ui/check-box';
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2020-06-15 21:08:53 +02:00
|
|
|
export default class ConnectedAccountsPermissions extends PureComponent {
|
2020-05-15 20:53:52 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
permissions: [],
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
2020-11-03 00:41:28 +01:00
|
|
|
permissions: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape({
|
|
|
|
key: PropTypes.string.isRequired,
|
|
|
|
}),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
state = {
|
|
|
|
expanded: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
toggleExpanded = () => {
|
|
|
|
this.setState((prevState) => ({
|
|
|
|
expanded: !prevState.expanded,
|
2021-02-04 19:15:23 +01:00
|
|
|
}));
|
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { permissions } = this.props;
|
|
|
|
const { t } = this.context;
|
|
|
|
const { expanded } = this.state;
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
if (permissions.length === 0) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2020-05-15 20:53:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="connected-accounts-permissions">
|
2020-11-03 00:41:28 +01:00
|
|
|
<p
|
|
|
|
className="connected-accounts-permissions__header"
|
|
|
|
onClick={this.toggleExpanded}
|
|
|
|
>
|
2020-05-15 20:53:52 +02:00
|
|
|
<strong>{t('permissions')}</strong>
|
|
|
|
<button
|
|
|
|
className={classnames('fas', {
|
|
|
|
'fa-angle-down': !expanded,
|
|
|
|
'fa-angle-up': expanded,
|
|
|
|
})}
|
|
|
|
title={t('showPermissions')}
|
|
|
|
/>
|
|
|
|
</p>
|
2020-05-20 22:42:18 +02:00
|
|
|
<div
|
2020-11-03 00:41:28 +01:00
|
|
|
className={classnames(
|
|
|
|
'connected-accounts-permissions__list-container',
|
|
|
|
{
|
|
|
|
'connected-accounts-permissions__list-container--expanded': expanded,
|
|
|
|
},
|
|
|
|
)}
|
2020-05-20 22:42:18 +02:00
|
|
|
>
|
|
|
|
<p>{t('authorizedPermissions')}:</p>
|
|
|
|
<ul className="connected-accounts-permissions__list">
|
2020-05-29 00:53:11 +02:00
|
|
|
{permissions.map(({ key: permissionName }) => (
|
2020-11-03 00:41:28 +01:00
|
|
|
<li
|
|
|
|
key={permissionName}
|
|
|
|
className="connected-accounts-permissions__list-item"
|
|
|
|
>
|
|
|
|
<CheckBox
|
|
|
|
checked
|
|
|
|
disabled
|
|
|
|
id={permissionName}
|
|
|
|
className="connected-accounts-permissions__checkbox"
|
|
|
|
/>
|
2020-06-23 16:26:33 +02:00
|
|
|
<label htmlFor={permissionName}>{t(permissionName)}</label>
|
2020-05-20 22:42:18 +02:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
2020-05-15 20:53:52 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-05-15 20:53:52 +02:00
|
|
|
}
|
|
|
|
}
|