2023-04-03 19:33:54 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Box from '../../ui/box';
|
|
|
|
import {
|
|
|
|
AlignItems,
|
|
|
|
Color,
|
|
|
|
IconColor,
|
|
|
|
JustifyContent,
|
|
|
|
Size,
|
|
|
|
TextColor,
|
|
|
|
TextVariant,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import {
|
2023-04-19 23:16:49 +02:00
|
|
|
AvatarIcon,
|
|
|
|
Text,
|
2023-04-03 19:33:54 +02:00
|
|
|
Icon,
|
2023-04-19 23:16:49 +02:00
|
|
|
IconName,
|
|
|
|
IconSize,
|
|
|
|
} from '../../component-library';
|
2023-04-03 19:33:54 +02:00
|
|
|
import { formatDate } from '../../../helpers/utils/util';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
import Tooltip from '../../ui/tooltip';
|
|
|
|
|
|
|
|
const PermissionCell = ({
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
weight,
|
|
|
|
avatarIcon,
|
|
|
|
dateApproved,
|
|
|
|
revoked,
|
|
|
|
}) => {
|
|
|
|
const t = useI18nContext();
|
|
|
|
|
|
|
|
let infoIconColor = IconColor.iconMuted;
|
2023-04-19 23:16:49 +02:00
|
|
|
let infoIcon = IconName.Info;
|
|
|
|
let iconColor = IconColor.primaryDefault;
|
2023-04-03 19:33:54 +02:00
|
|
|
let iconBackgroundColor = Color.primaryMuted;
|
|
|
|
|
|
|
|
if (!revoked && weight === 1) {
|
2023-04-19 23:16:49 +02:00
|
|
|
iconColor = IconColor.warningDefault;
|
2023-04-03 19:33:54 +02:00
|
|
|
iconBackgroundColor = Color.warningMuted;
|
|
|
|
infoIconColor = IconColor.warningDefault;
|
2023-04-19 23:16:49 +02:00
|
|
|
infoIcon = IconName.Danger;
|
2023-04-03 19:33:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dateApproved) {
|
2023-04-19 23:16:49 +02:00
|
|
|
iconColor = IconColor.iconMuted;
|
2023-04-03 19:33:54 +02:00
|
|
|
iconBackgroundColor = Color.backgroundAlternative;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (revoked) {
|
2023-04-19 23:16:49 +02:00
|
|
|
iconColor = IconColor.iconMuted;
|
2023-04-03 19:33:54 +02:00
|
|
|
iconBackgroundColor = Color.backgroundAlternative;
|
|
|
|
}
|
|
|
|
|
2023-04-14 12:04:23 +02:00
|
|
|
let permissionIcon = avatarIcon;
|
|
|
|
if (typeof avatarIcon !== 'string' && avatarIcon?.props?.iconName) {
|
|
|
|
permissionIcon = avatarIcon.props.iconName;
|
|
|
|
}
|
|
|
|
|
2023-04-03 19:33:54 +02:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className="permission-cell"
|
|
|
|
justifyContent={JustifyContent.center}
|
|
|
|
alignItems={AlignItems.flexStart}
|
|
|
|
marginLeft={4}
|
|
|
|
marginRight={4}
|
|
|
|
paddingTop={2}
|
|
|
|
paddingBottom={2}
|
|
|
|
>
|
|
|
|
<Box>
|
2023-04-14 12:04:23 +02:00
|
|
|
{typeof permissionIcon === 'string' ? (
|
2023-04-03 19:33:54 +02:00
|
|
|
<AvatarIcon
|
2023-04-14 12:04:23 +02:00
|
|
|
iconName={permissionIcon}
|
2023-04-19 23:16:49 +02:00
|
|
|
size={IconSize.Md}
|
2023-04-03 19:33:54 +02:00
|
|
|
iconProps={{
|
2023-04-19 23:16:49 +02:00
|
|
|
size: IconSize.Sm,
|
2023-04-03 19:33:54 +02:00
|
|
|
}}
|
|
|
|
color={iconColor}
|
|
|
|
backgroundColor={iconBackgroundColor}
|
|
|
|
/>
|
|
|
|
) : (
|
2023-04-14 12:04:23 +02:00
|
|
|
permissionIcon
|
2023-04-03 19:33:54 +02:00
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
<Box width="full" marginLeft={4} marginRight={4}>
|
|
|
|
<Text
|
|
|
|
size={Size.MD}
|
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
className={classnames('permission-cell__title', {
|
|
|
|
'permission-cell__title-revoked': revoked,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
size={Size.XS}
|
|
|
|
className="permission-cell__status"
|
|
|
|
variant={TextVariant.bodyXs}
|
|
|
|
color={TextColor.textAlternative}
|
|
|
|
>
|
|
|
|
{!revoked &&
|
|
|
|
(dateApproved
|
|
|
|
? t('approvedOn', [formatDate(dateApproved, 'yyyy-MM-dd')])
|
|
|
|
: t('permissionRequested'))}
|
|
|
|
{revoked ? t('permissionRevoked') : ''}
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
<Box>
|
|
|
|
<Tooltip html={<div>{description}</div>} position="bottom">
|
2023-04-19 23:16:49 +02:00
|
|
|
<Icon color={infoIconColor} name={infoIcon} size={IconSize.Sm} />
|
2023-04-03 19:33:54 +02:00
|
|
|
</Tooltip>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionCell.propTypes = {
|
|
|
|
title: PropTypes.oneOfType([
|
|
|
|
PropTypes.string.isRequired,
|
|
|
|
PropTypes.object.isRequired,
|
|
|
|
]),
|
|
|
|
description: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
|
|
weight: PropTypes.number,
|
|
|
|
avatarIcon: PropTypes.any.isRequired,
|
|
|
|
dateApproved: PropTypes.number,
|
|
|
|
revoked: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PermissionCell;
|