Add success message to subscription management form
[MAILPOET-1635]
This commit is contained in:
committed by
Veljko V
parent
7c2e9162a1
commit
c2c47a1c84
@ -440,7 +440,7 @@ div.mailpoet_form_slide_in.active {
|
||||
}
|
||||
}
|
||||
|
||||
// Manage Subscrition page
|
||||
// Manage Subscription page
|
||||
.mailpoet-manage-subscription {
|
||||
.mailpoet_text_label,
|
||||
.mailpoet_textarea_label,
|
||||
@ -451,4 +451,8 @@ div.mailpoet_form_slide_in.active {
|
||||
.mailpoet_date_label {
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
.mailpoet-submit-success {
|
||||
color: $color-input-success;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
@import 'settings/breakpoints';
|
||||
@import 'settings/grid';
|
||||
@import 'settings/colors';
|
||||
|
||||
// Tools
|
||||
// Default mixins and functions. Not producing any CSS.
|
||||
|
@ -54,6 +54,7 @@ class Manage {
|
||||
$subscriberData = $_POST['data'];
|
||||
$subscriberData = $this->fieldNameObfuscator->deobfuscateFormPayload($subscriberData);
|
||||
|
||||
$result = [];
|
||||
if (!empty($subscriberData['email'])) {
|
||||
$subscriber = Subscriber::where('email', $subscriberData['email'])->findOne();
|
||||
|
||||
@ -76,9 +77,10 @@ class Manage {
|
||||
$subscriber->getErrors();
|
||||
}
|
||||
}
|
||||
$result = ['success' => true];
|
||||
}
|
||||
|
||||
$this->urlHelper->redirectBack();
|
||||
$this->urlHelper->redirectBack($result);
|
||||
}
|
||||
|
||||
private function updateSubscriptions(Subscriber $subscriber, array $subscriberData) {
|
||||
|
@ -15,6 +15,9 @@ use MailPoet\Util\Url as UrlHelper;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class ManageSubscriptionFormRenderer {
|
||||
const FORM_STATE_SUCCESS = 'success';
|
||||
const FORM_STATE_NOT_SUBMITTED = 'not_submitted';
|
||||
|
||||
/** @var SettingsController */
|
||||
private $settings;
|
||||
|
||||
@ -54,7 +57,7 @@ class ManageSubscriptionFormRenderer {
|
||||
$this->templateRenderer = $templateRenderer;
|
||||
}
|
||||
|
||||
public function renderForm(Subscriber $subscriber): string {
|
||||
public function renderForm(Subscriber $subscriber, string $formState = self::FORM_STATE_NOT_SUBMITTED): string {
|
||||
$basicFields = $this->getBasicFields($subscriber);
|
||||
$customFields = $this->getCustomFields($subscriber);
|
||||
$segmentField = $this->getSegmentField($subscriber);
|
||||
@ -83,6 +86,7 @@ class ManageSubscriptionFormRenderer {
|
||||
'token' => $this->linkTokens->getToken($subscriber),
|
||||
'editEmailInfo' => __('Need to change your email address? Unsubscribe here, then simply sign up again.', 'mailpoet'),
|
||||
'formHtml' => $this->formRenderer->renderBlocks($form, [], $honeypot = false),
|
||||
'formState' => $formState,
|
||||
];
|
||||
|
||||
if ($subscriber->isWPUser() || $subscriber->isWooCommerceUser()) {
|
||||
|
@ -358,9 +358,13 @@ class Pages {
|
||||
return $this->wp->__('Subscription management form is only available to mailing lists subscribers.', 'mailpoet');
|
||||
}
|
||||
|
||||
$formStatus = isset($_GET['success']) && $_GET['success']
|
||||
? ManageSubscriptionFormRenderer::FORM_STATE_SUCCESS
|
||||
: ManageSubscriptionFormRenderer::FORM_STATE_NOT_SUBMITTED;
|
||||
|
||||
return $this->wp->applyFilters(
|
||||
'mailpoet_manage_subscription_page',
|
||||
$this->manageSubscriptionFormRenderer->renderForm($subscriber)
|
||||
$this->manageSubscriptionFormRenderer->renderForm($subscriber, $formStatus)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ class ManageSubscriptionLinkCest {
|
||||
$i->click('Manage your subscription');
|
||||
$i->switchToNextTab();
|
||||
$i->waitForText('Manage your subscription');
|
||||
$successMessage = 'Your preferences have been saved.';
|
||||
$i->dontSee($successMessage);
|
||||
|
||||
$formStatusElement = '[data-automation-id="form_status"]';
|
||||
|
||||
@ -52,6 +54,7 @@ class ManageSubscriptionLinkCest {
|
||||
$i->click('Save');
|
||||
$i->waitForElement($formStatusElement);
|
||||
$i->seeOptionIsSelected($formStatusElement, 'Unsubscribed');
|
||||
$i->see($successMessage);
|
||||
|
||||
// change status back to subscribed
|
||||
$i->selectOption($formStatusElement, 'Subscribed');
|
||||
|
@ -11,5 +11,10 @@
|
||||
<span style="font-size:85%;"><%= editEmailInfo|raw %></span>
|
||||
</p>
|
||||
<%= formHtml|raw %>
|
||||
<% if formState == 'success' %>
|
||||
<p class="mailpoet-submit-success">
|
||||
<%= _x('Your preferences have been saved.', 'success message after saving subscription settings') %>
|
||||
</p>
|
||||
<% endif %>
|
||||
</form>
|
||||
<% endblock %>
|
||||
|
Reference in New Issue
Block a user