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