Add saved/activated notices when redirecting back to automation listing

[MAILPOET-5779]
This commit is contained in:
Jan Jakes
2024-01-15 19:59:16 +01:00
committed by Aschepikov
parent c1f2d48811
commit f4ac59f685
2 changed files with 16 additions and 8 deletions

View File

@@ -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'),

View File

@@ -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&notice=${action}`;
} else {
this.props.history.push(`/${this.state.item.type}`);
}