import MailPoet from 'mailpoet'; import PropTypes from 'prop-types'; import React from 'react'; import ReactDOM from 'react-dom'; class ConfirmAlert extends React.Component { static propTypes = { title: PropTypes.string, message: PropTypes.string.isRequired, cancelLabel: PropTypes.string, confirmLabel: PropTypes.string, onConfirm: PropTypes.func.isRequired, } static defaultProps = { title: MailPoet.I18n.t('confirmTitle'), cancelLabel: MailPoet.I18n.t('cancelLabel'), confirmLabel: MailPoet.I18n.t('confirmLabel'), } constructor(props) { super(props); this.state = { show: true }; } componentWillUpdate = () => { if (!this.state.show) { this.setState({ show: true }); } } onClose = () => { this.setState({ show: false }); } onConfirm = () => { this.onClose(); this.props.onConfirm(); } render() { const { title, message, confirmLabel, cancelLabel, } = this.props; return (this.state.show && (
) ); } } export default function confirmAlert(props) { ReactDOM.render(, document.getElementById('mailpoet_confirm_alert_holder')); }