import React, { useState, useRef } from 'react'; import PropTypes from 'prop-types'; import { useDispatch } from 'react-redux'; import Box from '../../ui/box'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { IconName, ButtonIcon } from '../../component-library'; import { Text } from '../../component-library/text/deprecated'; import { Menu, MenuItem } from '../../ui/menu'; import { TextColor, TextVariant, } from '../../../helpers/constants/design-system'; import Popover from '../../ui/popover/popover.component'; import { DynamicSnapPermissions } from '../../../../shared/constants/snaps/permissions'; import { revokeDynamicSnapPermissions } from '../../../store/actions'; export const PermissionCellOptions = ({ snapId, permissionName, description, }) => { const t = useI18nContext(); const dispatch = useDispatch(); const ref = useRef(false); const [showOptions, setShowOptions] = useState(false); const [showDetails, setShowDetails] = useState(false); const isRevokable = DynamicSnapPermissions.includes(permissionName); const handleOpen = () => { setShowOptions(true); }; const handleClose = () => { setShowOptions(false); }; const handleDetailsOpen = () => { setShowOptions(false); setShowDetails(true); }; const handleDetailsClose = () => { setShowOptions(false); setShowDetails(false); }; const handleRevokePermission = () => { setShowOptions(false); dispatch(revokeDynamicSnapPermissions(snapId, [permissionName])); }; return ( {showOptions && ( {t('details')} {isRevokable && ( {t('revokePermission')} )} )} {showDetails && ( {description} )} ); }; PermissionCellOptions.propTypes = { snapId: PropTypes.string.isRequired, permissionName: PropTypes.string.isRequired, description: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), };