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) {
|
2022-12-01 14:38:56 +01:00
|
|
|
const permissions = getPermissionDescription(
|
2022-08-18 17:07:34 +02:00
|
|
|
t,
|
|
|
|
permissionName,
|
|
|
|
permissionValue,
|
|
|
|
);
|
|
|
|
|
2022-12-01 14:38:56 +01:00
|
|
|
return permissions.map(({ label, leftIcon, rightIcon }, index) => (
|
|
|
|
<div className="permission" key={`${permissionName}-${index}`}>
|
2022-08-18 17:07:34 +02:00
|
|
|
<i className={leftIcon} />
|
|
|
|
{label}
|
|
|
|
{rightIcon && <i className={rightIcon} />}
|
2022-12-01 14:38:56 +01:00
|
|
|
</div>
|
|
|
|
));
|
2022-08-18 17:07:34 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|