mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
c052ab1334
refs https://github.com/TryGhost/Team/issues/1469 - default newsletters were set for new members added on members list except "add yourself" feature - updates default newsletters for new member added via "Add yourself" button
49 lines
1.3 KiB
JavaScript
49 lines
1.3 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;
|
|
|
|
@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 successfully added yourself as a member.'
|
|
}
|
|
);
|
|
|
|
return member;
|
|
} catch (error) {
|
|
if (error) {
|
|
this.notifications.showAPIError(error, {key: 'member.save'});
|
|
}
|
|
}
|
|
}
|
|
}
|