import PropTypes from 'prop-types'; import React, { useCallback, useState } from 'react'; import { PageContainerFooter } from '../../../../components/ui/page-container'; import PermissionsConnectPermissionList from '../../../../components/app/permissions-connect-permission-list'; import PermissionsConnectFooter from '../../../../components/app/permissions-connect-footer'; import PermissionConnectHeader from '../../../../components/app/permissions-connect-header'; import { useI18nContext } from '../../../../hooks/useI18nContext'; import SnapInstallWarning from '../../../../components/app/flask/snap-install-warning'; import Box from '../../../../components/ui/box/box'; import { ALIGN_ITEMS, BLOCK_SIZES, BORDER_STYLE, FLEX_DIRECTION, JUSTIFY_CONTENT, TYPOGRAPHY, } from '../../../../helpers/constants/design-system'; import Typography from '../../../../components/ui/typography'; import { getSnapInstallWarnings } from '../util'; export default function SnapInstall({ request, approveSnapInstall, rejectSnapInstall, targetSubjectMetadata, }) { const t = useI18nContext(); const [isShowingWarning, setIsShowingWarning] = useState(false); const onCancel = useCallback( () => rejectSnapInstall(request.metadata.id), [request, rejectSnapInstall], ); const onSubmit = useCallback( () => approveSnapInstall(request.metadata.id), [request, approveSnapInstall], ); const hasPermissions = request?.permissions && Object.keys(request.permissions).length > 0; const warnings = getSnapInstallWarnings( request.permissions, targetSubjectMetadata, t, ); const shouldShowWarning = warnings.length > 0; return ( {hasPermissions && ( <> {t('snapRequestsPermission')} )} setIsShowingWarning(true) : onSubmit } submitText={t(hasPermissions ? 'approveAndInstall' : 'install')} /> {isShowingWarning && ( setIsShowingWarning(false)} onSubmit={onSubmit} warnings={warnings} /> )} ); } SnapInstall.propTypes = { request: PropTypes.object.isRequired, approveSnapInstall: PropTypes.func.isRequired, rejectSnapInstall: PropTypes.func.isRequired, targetSubjectMetadata: PropTypes.shape({ iconUrl: PropTypes.string, name: PropTypes.string, origin: PropTypes.string.isRequired, sourceCode: PropTypes.string, version: PropTypes.string, }).isRequired, };