Call different actions for standard and automated newsletters on Send step
- converted save and setStatus method of Newsletters endpoint - updated pause/resume mixin for notification & welcome listings - use 'newsletter_id' instead of 'id' in SendingQueue endpoint (less confusing) - added NOT_FOUND constant to APIError - fixed unit test for Newsletters endpoint save and added test for setStatus
This commit is contained in:
@@ -9,11 +9,18 @@ const _QueueMixin = {
|
||||
endpoint: 'sendingQueue',
|
||||
action: 'pause',
|
||||
data: {
|
||||
id: newsletter.id
|
||||
newsletter_id: newsletter.id
|
||||
}
|
||||
}).done(function() {
|
||||
jQuery('#resume_'+newsletter.id).show();
|
||||
jQuery('#pause_'+newsletter.id).hide();
|
||||
}).fail((response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function(error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
resumeSending: function(newsletter) {
|
||||
@@ -21,11 +28,18 @@ const _QueueMixin = {
|
||||
endpoint: 'sendingQueue',
|
||||
action: 'resume',
|
||||
data: {
|
||||
id: newsletter.id
|
||||
newsletter_id: newsletter.id
|
||||
}
|
||||
}).done(function() {
|
||||
jQuery('#pause_'+newsletter.id).show();
|
||||
jQuery('#resume_'+newsletter.id).hide();
|
||||
}).fail((response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function(error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
renderQueueStatus: function(newsletter) {
|
||||
|
@@ -158,20 +158,18 @@ const NewsletterListNotification = React.createClass({
|
||||
id: ~~(e.target.getAttribute('data-id')),
|
||||
status: e.target.value
|
||||
}
|
||||
}).done(function(response) {
|
||||
if (response.result === false) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('postNotificationActivationFailed'));
|
||||
|
||||
// reset value to actual newsletter's status
|
||||
e.target.value = response.status;
|
||||
} else {
|
||||
if (response.status === 'active') {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('postNotificationActivated'));
|
||||
}
|
||||
// force refresh of listing so that groups are updated
|
||||
this.forceUpdate();
|
||||
}).done((response) => {
|
||||
if (response.data.status === 'active') {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('postNotificationActivated'));
|
||||
}
|
||||
}.bind(this));
|
||||
// force refresh of listing so that groups are updated
|
||||
this.forceUpdate();
|
||||
}).fail((response) => {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('postNotificationActivationFailed'));
|
||||
|
||||
// reset value to actual newsletter's status
|
||||
e.target.value = response.status;
|
||||
});
|
||||
},
|
||||
renderStatus: function(newsletter) {
|
||||
return (
|
||||
|
@@ -156,20 +156,18 @@ const NewsletterListWelcome = React.createClass({
|
||||
id: ~~(e.target.getAttribute('data-id')),
|
||||
status: e.target.value
|
||||
}
|
||||
}).done(function(response) {
|
||||
if (response.result === false) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('welcomeEmailActivationFailed'));
|
||||
|
||||
// reset value to actual newsletter's status
|
||||
e.target.value = response.status;
|
||||
} else {
|
||||
if (response.status === 'active') {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('welcomeEmailActivated'));
|
||||
}
|
||||
// force refresh of listing so that groups are updated
|
||||
this.forceUpdate();
|
||||
}).done((response) => {
|
||||
if (response.data.status === 'active') {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('welcomeEmailActivated'));
|
||||
}
|
||||
}.bind(this));
|
||||
// force refresh of listing so that groups are updated
|
||||
this.forceUpdate();
|
||||
}).fail((response) => {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('welcomeEmailActivationFailed'));
|
||||
|
||||
// reset value to actual newsletter's status
|
||||
e.target.value = response.status;
|
||||
});
|
||||
},
|
||||
renderStatus: function(newsletter) {
|
||||
let total_sent;
|
||||
|
@@ -87,6 +87,15 @@ define(
|
||||
handleSend: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const onFail = (response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function(error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if(!this.isValid()) {
|
||||
jQuery('#mailpoet_newsletter').parsley().validate();
|
||||
} else {
|
||||
@@ -96,43 +105,57 @@ define(
|
||||
endpoint: 'newsletters',
|
||||
action: 'save',
|
||||
data: this.state.item,
|
||||
}).then((response) => {
|
||||
if (response.result === true) {
|
||||
return MailPoet.Ajax.post({
|
||||
endpoint: 'sendingQueue',
|
||||
action: 'add',
|
||||
data: {
|
||||
id: this.props.params.id
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return response;
|
||||
}).done((response) => {
|
||||
switch (response.data.type) {
|
||||
case 'notification':
|
||||
case 'welcome':
|
||||
return MailPoet.Ajax.post({
|
||||
endpoint: 'newsletters',
|
||||
action: 'setStatus',
|
||||
data: {
|
||||
id: this.props.params.id,
|
||||
status: 'active'
|
||||
}
|
||||
}).done((response) => {
|
||||
// redirect to listing based on newsletter type
|
||||
this.context.router.push(`/${ this.state.item.type || '' }`);
|
||||
|
||||
// display success message depending on newsletter type
|
||||
if (response.data.type === 'welcome') {
|
||||
MailPoet.Notice.success(
|
||||
MailPoet.I18n.t('welcomeEmailActivated')
|
||||
);
|
||||
} else if (response.data.type === 'notification') {
|
||||
MailPoet.Notice.success(
|
||||
MailPoet.I18n.t('postNotificationActivated')
|
||||
);
|
||||
}
|
||||
}).fail(onFail);
|
||||
default:
|
||||
return MailPoet.Ajax.post({
|
||||
endpoint: 'sendingQueue',
|
||||
action: 'add',
|
||||
data: {
|
||||
newsletter_id: this.props.params.id
|
||||
}
|
||||
}).done((response) => {
|
||||
// redirect to listing based on newsletter type
|
||||
this.context.router.push(`/${ this.state.item.type || '' }`);
|
||||
|
||||
if (response.data.status === 'scheduled') {
|
||||
MailPoet.Notice.success(
|
||||
MailPoet.I18n.t('newsletterHasBeenScheduled')
|
||||
);
|
||||
} else {
|
||||
MailPoet.Notice.success(
|
||||
MailPoet.I18n.t('newsletterBeingSent')
|
||||
);
|
||||
}
|
||||
}).fail(onFail);
|
||||
}
|
||||
}).always(() => {
|
||||
this.setState({ loading: false });
|
||||
}).done((response) => {
|
||||
// redirect to listing based on newsletter type
|
||||
this.context.router.push(`/${ this.state.item.type || '' }`);
|
||||
// display success message depending on newsletter type
|
||||
if (this.state.item.type === 'welcome') {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('welcomeEmailActivated'));
|
||||
} else if (this.state.item.type === 'notification') {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('postNotificationActivated'));
|
||||
} else {
|
||||
if (response.data.status === 'scheduled') {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('newsletterHasBeenScheduled'));
|
||||
} else {
|
||||
MailPoet.Notice.success(MailPoet.I18n.t('newsletterBeingSent'));
|
||||
}
|
||||
}
|
||||
}).fail((response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function(error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
}).fail(onFail);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
@@ -134,16 +134,17 @@ define(
|
||||
id: this.props.params.id,
|
||||
body: body
|
||||
}
|
||||
}).done(function(response) {
|
||||
if(response.result === true) {
|
||||
// TODO: Move this URL elsewhere
|
||||
window.location = 'admin.php?page=mailpoet-newsletter-editor&id=' + this.props.params.id;
|
||||
} else {
|
||||
response.errors.map(function(error) {
|
||||
MailPoet.Notice.error(error);
|
||||
});
|
||||
}).done((response) => {
|
||||
// TODO: Move this URL elsewhere
|
||||
window.location = 'admin.php?page=mailpoet-newsletter-editor&id=' + response.data.id;
|
||||
}).fail((response) => {
|
||||
if (response.errors.length > 0) {
|
||||
MailPoet.Notice.error(
|
||||
response.errors.map(function(error) { return error.message; }),
|
||||
{ scroll: true }
|
||||
);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
handleDeleteTemplate: function(template) {
|
||||
this.setState({ loading: true });
|
||||
|
Reference in New Issue
Block a user