mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
Handled duplicate newsletter name errors correctly
refs https://github.com/TryGhost/Team/issues/1564 - Shows the error inline - Depends on https://github.com/TryGhost/Ghost/pull/14694
This commit is contained in:
parent
ae1010ea03
commit
bb4b3a7eec
@ -43,30 +43,41 @@ export default class EditNewsletterModal extends Component {
|
||||
|
||||
@task
|
||||
*saveTask() {
|
||||
const newsletter = this.args.data.newsletter;
|
||||
try {
|
||||
yield this.args.data.newsletter.validate({});
|
||||
yield newsletter.validate({});
|
||||
|
||||
const newEmail = this.args.data.newsletter.senderEmail;
|
||||
const newEmail = newsletter.senderEmail;
|
||||
|
||||
const result = yield this.args.data.newsletter.save();
|
||||
const result = yield newsletter.save();
|
||||
|
||||
if (result._meta?.sent_email_verification) {
|
||||
yield this.modals.open(ConfirmNewsletterEmailModal, {
|
||||
newEmail,
|
||||
currentEmail: this.args.data.newsletter.senderEmail
|
||||
currentEmail: newsletter.senderEmail
|
||||
});
|
||||
}
|
||||
|
||||
this.args.data.afterSave?.(result);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (e === undefined) {
|
||||
} catch (error) {
|
||||
if (error === undefined) {
|
||||
// Validation error
|
||||
return;
|
||||
}
|
||||
|
||||
throw e;
|
||||
// Do we have an error that we can show inline?
|
||||
if (error.payload && error.payload.errors) {
|
||||
for (const payloadError of error.payload.errors) {
|
||||
if (payloadError.type === 'ValidationError' && payloadError.property && (payloadError.context || payloadError.message)) {
|
||||
// Context has a better error message for validation errors
|
||||
newsletter.errors.add(payloadError.property, payloadError.context || payloadError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,23 +39,34 @@ export default class NewNewsletterModal extends Component {
|
||||
|
||||
@task
|
||||
*saveTask() {
|
||||
const newsletter = this.args.data.newsletter;
|
||||
try {
|
||||
yield this.args.data.newsletter.validate({});
|
||||
yield newsletter.validate({});
|
||||
|
||||
const result = yield this.args.data.newsletter.save({
|
||||
const result = yield newsletter.save({
|
||||
adapterOptions: {optInExisting: this.optInExisting}
|
||||
});
|
||||
|
||||
this.args.data.afterSave?.(result);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (e === undefined) {
|
||||
} catch (error) {
|
||||
if (error === undefined) {
|
||||
// Validation error
|
||||
return;
|
||||
}
|
||||
|
||||
throw e;
|
||||
// Do we have an error that we can show inline?
|
||||
if (error.payload && error.payload.errors) {
|
||||
for (const payloadError of error.payload.errors) {
|
||||
if (payloadError.type === 'ValidationError' && payloadError.property && (payloadError.context || payloadError.message)) {
|
||||
// Context has a better error message for validation errors
|
||||
newsletter.errors.add(payloadError.property, payloadError.context || payloadError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user