Add saved/activated notices when redirecting back to automation listing
[MAILPOET-5779]
This commit is contained in:
@@ -5,6 +5,8 @@ import { __ } from '@wordpress/i18n';
|
||||
import { getQueryArg, removeQueryArgs } from '@wordpress/url';
|
||||
|
||||
export const LISTING_NOTICES = {
|
||||
automationActivated: 'activated',
|
||||
automationSaved: 'saved',
|
||||
automationDeleted: 'deleted',
|
||||
automationHadBeenDeleted: 'had-been-deleted',
|
||||
} as const;
|
||||
@@ -14,8 +16,14 @@ export function useAutomationListingNotices(): void {
|
||||
|
||||
useEffect(() => {
|
||||
const notice = getQueryArg(window.location.href, 'notice');
|
||||
|
||||
if (notice === LISTING_NOTICES.automationDeleted) {
|
||||
if (notice === LISTING_NOTICES.automationActivated) {
|
||||
createNotice('success', __('Your automation is now active.', 'mailpoet'));
|
||||
} else if (notice === LISTING_NOTICES.automationSaved) {
|
||||
createNotice(
|
||||
'success',
|
||||
__('Your automation has been saved.', 'mailpoet'),
|
||||
);
|
||||
} else if (notice === LISTING_NOTICES.automationDeleted) {
|
||||
createNotice(
|
||||
'success',
|
||||
__('1 automation moved to the Trash.', 'mailpoet'),
|
||||
|
@@ -445,7 +445,7 @@ class NewsletterSendComponent extends Component<
|
||||
this.props.history.push(`/send/congratulate/${this.state.item.id}`);
|
||||
return;
|
||||
}
|
||||
this.redirectToListing();
|
||||
this.redirectToListing('activated');
|
||||
|
||||
// prepare segments
|
||||
let filters = [];
|
||||
@@ -504,7 +504,7 @@ class NewsletterSendComponent extends Component<
|
||||
this.props.history.push(`/send/congratulate/${this.state.item.id}`);
|
||||
return;
|
||||
}
|
||||
this.redirectToListing();
|
||||
this.redirectToListing('activated');
|
||||
|
||||
// display success message depending on newsletter type
|
||||
const opts = this.state.item.options;
|
||||
@@ -579,7 +579,7 @@ class NewsletterSendComponent extends Component<
|
||||
},
|
||||
})
|
||||
.done(() => {
|
||||
this.redirectToListing();
|
||||
this.redirectToListing('activated');
|
||||
this.context.notices.success(
|
||||
<p>
|
||||
{__('The newsletter sending has been resumed.', 'mailpoet')}
|
||||
@@ -610,17 +610,17 @@ class NewsletterSendComponent extends Component<
|
||||
);
|
||||
})
|
||||
.done(() => {
|
||||
this.redirectToListing();
|
||||
this.redirectToListing('saved');
|
||||
})
|
||||
.fail((err) => {
|
||||
this.showError(err);
|
||||
});
|
||||
};
|
||||
|
||||
redirectToListing = () => {
|
||||
redirectToListing = (action: 'activated' | 'saved') => {
|
||||
// redirect to listing based on newsletter type
|
||||
if (['automatic', 'welcome'].includes(this.state.item.type)) {
|
||||
window.location.href = 'admin.php?page=mailpoet-automation';
|
||||
window.location.href = `admin.php?page=mailpoet-automation¬ice=${action}`;
|
||||
} else {
|
||||
this.props.history.push(`/${this.state.item.type}`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user