import { Dialog } from '@automattic/components'; import { Button, Modal } from '@wordpress/components'; import clsx from 'clsx'; import { localize } from 'i18n-calypso'; import PropTypes from 'prop-types'; import { Component } from 'react'; import './dialog.scss'; class AcceptDialog extends Component { static displayName = 'AcceptDialog'; static propTypes = { translate: PropTypes.func, message: PropTypes.node, title: PropTypes.node, onClose: PropTypes.func.isRequired, confirmButtonText: PropTypes.node, cancelButtonText: PropTypes.node, options: PropTypes.shape( { isScary: PropTypes.bool, additionalClassNames: PropTypes.string, useModal: PropTypes.bool, modalOptions: PropTypes.object, } ), }; state = { isVisible: true }; onClose = ( action ) => { this.setState( { isVisible: false } ); this.props.onClose( 'accept' === action ); }; getActionButtons = () => { const { options } = this.props; const isScary = options && options.isScary; const additionalClassNames = clsx( { 'is-scary': isScary } ); return [ { action: 'cancel', label: this.props.cancelButtonText ? this.props.cancelButtonText : this.props.translate( 'Cancel' ), additionalClassNames: 'is-cancel', }, { action: 'accept', label: this.props.confirmButtonText ? this.props.confirmButtonText : this.props.translate( 'OK' ), isPrimary: true, additionalClassNames, }, ]; }; render() { if ( ! this.state.isVisible ) { return null; } if ( this.props.options?.useModal ) { return ( { this.props.message } { this.getActionButtons().map( ( button ) => ( this.onClose( button.action ) } variant={ button.isPrimary ? 'primary' : 'secondary' } className={ button.additionalClassNames } > { button.label } ) ) } ); } return ( { this.props.message } ); } } export default localize( AcceptDialog );