2022-03-04 17:56:31 +01:00
|
|
|
import React from 'react';
|
2021-12-02 18:22:18 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2022-03-14 19:26:02 +01:00
|
|
|
import { getPermissionDescription } from '../../../helpers/utils/permission';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2021-12-02 18:22:18 +01:00
|
|
|
|
2022-08-18 17:07:34 +02:00
|
|
|
/**
|
|
|
|
* Get one or more permission descriptions for a permission name.
|
|
|
|
*
|
|
|
|
* @param t - The translation function.
|
|
|
|
* @param permissionName - The name of the permission to request.
|
|
|
|
* @param permissionValue - The value of the permission to request.
|
|
|
|
* @returns {JSX.Element[]} An array of permission description nodes.
|
|
|
|
*/
|
|
|
|
function getDescriptionNodes(t, permissionName, permissionValue) {
|
|
|
|
const { label, leftIcon, rightIcon } = getPermissionDescription(
|
|
|
|
t,
|
|
|
|
permissionName,
|
|
|
|
permissionValue,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (Array.isArray(label)) {
|
|
|
|
return label.map((labelValue, index) => (
|
|
|
|
<div className="permission" key={`${permissionName}-${index}`}>
|
|
|
|
<i className={leftIcon} />
|
|
|
|
{labelValue}
|
|
|
|
{rightIcon && <i className={rightIcon} />}
|
|
|
|
</div>
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
<div className="permission" key={permissionName}>
|
|
|
|
<i className={leftIcon} />
|
|
|
|
{label}
|
|
|
|
{rightIcon && <i className={rightIcon} />}
|
|
|
|
</div>,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-12-02 18:22:18 +01:00
|
|
|
export default function PermissionsConnectPermissionList({ permissions }) {
|
2022-03-14 19:26:02 +01:00
|
|
|
const t = useI18nContext();
|
2021-12-02 18:22:18 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="permissions-connect-permission-list">
|
2022-08-18 17:07:34 +02:00
|
|
|
{Object.entries(permissions).reduce(
|
|
|
|
(target, [permissionName, permissionValue]) =>
|
|
|
|
target.concat(
|
|
|
|
getDescriptionNodes(t, permissionName, permissionValue),
|
|
|
|
),
|
|
|
|
[],
|
|
|
|
)}
|
2021-12-02 18:22:18 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
PermissionsConnectPermissionList.propTypes = {
|
2022-02-15 01:02:51 +01:00
|
|
|
permissions: PropTypes.object.isRequired,
|
2021-12-02 18:22:18 +01:00
|
|
|
};
|