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 { AvatarIcon, Icon, IconName, IconSize, Text, } from '../../component-library'; import { formatDate } from '../../../helpers/utils/util'; import { useI18nContext } from '../../../hooks/useI18nContext'; import Tooltip from '../../ui/tooltip'; import { PermissionCellOptions } from './permission-cell-options'; const PermissionCell = ({ snapId, permissionName, title, description, weight, avatarIcon, dateApproved, revoked, showOptions, }) => { const t = useI18nContext(); let infoIconColor = IconColor.iconMuted; let infoIcon = IconName.Info; let iconColor = IconColor.primaryDefault; let iconBackgroundColor = Color.primaryMuted; if (!revoked && weight === 1) { iconColor = IconColor.warningDefault; iconBackgroundColor = Color.warningMuted; infoIconColor = IconColor.warningDefault; infoIcon = IconName.Danger; } if (dateApproved) { iconColor = IconColor.iconMuted; iconBackgroundColor = Color.backgroundAlternative; } if (revoked) { iconColor = IconColor.iconMuted; iconBackgroundColor = Color.backgroundAlternative; } let permissionIcon = avatarIcon; if (typeof avatarIcon !== 'string' && avatarIcon?.props?.iconName) { permissionIcon = avatarIcon.props.iconName; } return ( {typeof permissionIcon === 'string' ? ( ) : ( permissionIcon )} {title} {!revoked && (dateApproved ? t('approvedOn', [formatDate(dateApproved, 'yyyy-MM-dd')]) : t('permissionRequested'))} {revoked ? t('permissionRevoked') : ''} {showOptions && snapId ? ( ) : ( {description}} position="bottom"> )} ); }; PermissionCell.propTypes = { snapId: PropTypes.string, permissionName: PropTypes.string.isRequired, 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, showOptions: PropTypes.bool, }; export default PermissionCell;