Ghost/ghost/admin/app/components/gh-members-no-members.js
Peter Zimon 770f657ae9
Improve messaging and error handling (#20078)
ref DES-228

This PR updates messaging and error handling in order to make Ghost calmer and friendlier. High level summary of the changes:

- Removed all onBlur validation in Settings -> now it’s possible to just click around without being warned to fill mandatory fields
- Removed  lot of technical errors like `ValidationError: Validation (isEmpty) failed for locale`
- Completely removed the red background toast notifications, it was aggressive and raw esp. on the top
- Removed some unnecessary notifications (e.g. when removing a webhook, the removal already communicates the result)
- Now we show field errors on submitting forms, and in case of an error we show a “Retry” button in Settings too. This allowed to remove a lot of unnecessary error messages, like the big error message on the top, plus it’s consistent with the patterns outside Settings.
- Notification style is white now with filled color icons which makes everything much calmer and more refined.
- Removes redundant copy (e.g. "successful(ly)") from notifications

---------

Co-authored-by: Sodbileg Gansukh <sodbileg.gansukh@gmail.com>
2024-05-14 09:31:19 +02:00

53 lines
1.5 KiB
JavaScript

import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
export default class GhMembersNoMembersComponent extends Component {
@service session;
@service store;
@service notifications;
@service settings;
@service membersCountCache;
@action
addYourself() {
return this.addTask.perform();
}
@task({drop: true})
*addTask() {
const user = yield this.session.user;
const defaultNewsletters = yield this.store.query('newsletter', {filter: 'status:active+subscribe_on_signup:true+visibility:members'});
const member = this.store.createRecord('member', {
email: user.get('email'),
name: user.get('name'),
newsletters: defaultNewsletters
});
try {
yield member.save();
if (this.args.afterCreate) {
this.args.afterCreate();
}
this.notifications.showNotification('Member added',
{
description: 'You\'ve added yourself as a member.'
}
);
// force update the member count; this otherwise only updates every minute
yield this.membersCountCache.count({});
return member;
} catch (error) {
if (error) {
this.notifications.showAPIError(error, {key: 'member.save'});
}
}
}
}