Reuse the new notice for a similar forgotten MSS notice

[MAILPOET-3830]
This commit is contained in:
wxa
2021-10-05 14:49:32 +03:00
committed by Veljko V
parent dbb52a758e
commit 516e5fbb14
4 changed files with 22 additions and 24 deletions

View File

@@ -38,13 +38,13 @@ export const addStatsCTAAction = (actions) => {
export const checkMailerStatus = (state) => { export const checkMailerStatus = (state) => {
if (state.meta.mta_log.error && state.meta.mta_log.error.operation === 'authorization') { if (state.meta.mta_log.error && state.meta.mta_log.error.operation === 'authorization') {
MailPoet.Notice.hide('mailpoet_notice_being_sent'); MailPoet.Notice.hide('mailpoet_notice_being_sent');
if (state.meta.mta_log.error.error_message.indexOf('mailpoet-js-button-resume-sending') >= 0) {
jQuery('.mailpoet-js-error-unauthorized-emails-notice').hide(); // prevent duplicate notices
}
MailPoet.Notice.error( MailPoet.Notice.error(
state.meta.mta_log.error.error_message, state.meta.mta_log.error.error_message,
{ static: true, id: 'mailpoet_authorization_error' } { static: true, id: 'mailpoet_authorization_error' }
); );
jQuery('.js-button-resume-sending').on('click', () => {
jQuery('[data-id="mailpoet_authorization_error"]').slideUp();
});
} }
}; };

View File

@@ -8,6 +8,7 @@ use MailPoet\Mailer\MailerError;
use MailPoet\Mailer\SubscriberError; use MailPoet\Mailer\SubscriberError;
use MailPoet\Services\Bridge\API; use MailPoet\Services\Bridge\API;
use MailPoet\Util\Helpers; use MailPoet\Util\Helpers;
use MailPoet\Util\Notices\UnauthorizedEmailNotice;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class MailPoetMapper { class MailPoetMapper {
@@ -93,21 +94,10 @@ class MailPoetMapper {
} }
private function getUnauthorizedEmailMessage($sender) { private function getUnauthorizedEmailMessage($sender) {
$email = $sender ? $sender['from_email'] : null; $email = $sender ? $sender['from_email'] : WPFunctions::get()->__('Unknown address');
$message = '<p>'; $validationError = ['invalid_sender_address' => $email];
$message .= sprintf(WPFunctions::get()->__('The MailPoet Sending Service did not send your latest email because the address %s is not yet authorized.', 'mailpoet'), '<i>' . ( $email ?: WPFunctions::get()->__('Unknown address') ) . '</i>' ); $notice = new UnauthorizedEmailNotice(WPFunctions::get(), null);
$message .= '</p><p>'; $message = $notice->getMessage($validationError);
$message .= Helpers::replaceLinkTags(
WPFunctions::get()->__('[link]Authorize your email in your account now.[/link]', 'mailpoet'),
'https://account.mailpoet.com/authorization',
[
'class' => 'button button-primary',
'target' => '_blank',
'rel' => 'noopener noreferrer',
]
);
$message .= ' &nbsp; <button class="button mailpoet-js-button-resume-sending">' . WPFunctions::get()->__('Resume sending', 'mailpoet') . '</button>';
$message .= '</p>';
return $message; return $message;
} }

View File

@@ -44,7 +44,7 @@ class PermanentNotices {
$this->wp = $wp; $this->wp = $wp;
$this->phpVersionWarnings = new PHPVersionWarnings(); $this->phpVersionWarnings = new PHPVersionWarnings();
$this->afterMigrationNotice = new AfterMigrationNotice(); $this->afterMigrationNotice = new AfterMigrationNotice();
$this->unauthorizedEmailsNotice = new UnauthorizedEmailNotice(SettingsController::getInstance(), $wp); $this->unauthorizedEmailsNotice = new UnauthorizedEmailNotice($wp, SettingsController::getInstance());
$this->unauthorizedEmailsInNewslettersNotice = new UnauthorizedEmailInNewslettersNotice(SettingsController::getInstance(), $wp); $this->unauthorizedEmailsInNewslettersNotice = new UnauthorizedEmailInNewslettersNotice(SettingsController::getInstance(), $wp);
$this->inactiveSubscribersNotice = new InactiveSubscribersNotice(SettingsController::getInstance(), $wp); $this->inactiveSubscribersNotice = new InactiveSubscribersNotice(SettingsController::getInstance(), $wp);
$this->blackFridayNotice = new BlackFridayNotice(); $this->blackFridayNotice = new BlackFridayNotice();

View File

@@ -12,21 +12,24 @@ class UnauthorizedEmailNotice {
const OPTION_NAME = 'unauthorized-email-addresses-notice'; const OPTION_NAME = 'unauthorized-email-addresses-notice';
/** @var SettingsController */ /** @var SettingsController|null */
private $settings; private $settings;
/** @var WPFunctions */ /** @var WPFunctions */
private $wp; private $wp;
public function __construct( public function __construct(
SettingsController $settings, WPFunctions $wp,
WPFunctions $wp SettingsController $settings = null
) { ) {
$this->settings = $settings; $this->settings = $settings;
$this->wp = $wp; $this->wp = $wp;
} }
public function init($shouldDisplay) { public function init($shouldDisplay) {
if (!$this->settings instanceof SettingsController) {
throw new \Exception('This method can only be called if SettingsController is provided');
}
$validationError = $this->settings->get(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING); $validationError = $this->settings->get(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING);
if ($shouldDisplay && isset($validationError['invalid_sender_address'])) { if ($shouldDisplay && isset($validationError['invalid_sender_address'])) {
return $this->display($validationError); return $this->display($validationError);
@@ -34,6 +37,12 @@ class UnauthorizedEmailNotice {
} }
public function display($validationError) { public function display($validationError) {
$message = $this->getMessage($validationError);
$extraClasses = 'mailpoet-js-error-unauthorized-emails-notice';
Notice::displayError($message, $extraClasses, self::OPTION_NAME, false, false);
}
public function getMessage($validationError) {
$message = $this->getMessageText($validationError); $message = $this->getMessageText($validationError);
$message .= sprintf( $message .= sprintf(
'<p>%s &nbsp; %s &nbsp; %s</p>', '<p>%s &nbsp; %s &nbsp; %s</p>',
@@ -41,8 +50,7 @@ class UnauthorizedEmailNotice {
$this->getDifferentEmailButton(), $this->getDifferentEmailButton(),
$this->getResumeSendingButton($validationError) $this->getResumeSendingButton($validationError)
); );
$extraClasses = 'mailpoet-js-error-unauthorized-emails-notice'; return $message;
Notice::displayError($message, $extraClasses, self::OPTION_NAME, false, false);
} }
private function getMessageText($validationError) { private function getMessageText($validationError) {