2020-06-05 10:49:56 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
2019-12-03 08:04:04 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2019-12-03 08:04:04 +03:00
|
|
|
|
2020-06-05 10:49:56 +03:00
|
|
|
export default class GhMembersNoMembersComponent extends Component {
|
|
|
|
@service session;
|
|
|
|
@service store;
|
|
|
|
@service notifications;
|
2022-02-11 21:06:48 +03:00
|
|
|
@service settings;
|
2024-01-31 00:08:27 +03:00
|
|
|
@service membersCountCache;
|
2019-12-03 08:04:04 +03:00
|
|
|
|
2020-06-05 10:49:56 +03:00
|
|
|
@action
|
|
|
|
addYourself() {
|
|
|
|
return this.addTask.perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
@task({drop: true})
|
|
|
|
*addTask() {
|
|
|
|
const user = yield this.session.user;
|
2022-04-26 10:32:21 +03:00
|
|
|
const defaultNewsletters = yield this.store.query('newsletter', {filter: 'status:active+subscribe_on_signup:true+visibility:members'});
|
2019-12-03 08:04:04 +03:00
|
|
|
|
|
|
|
const member = this.store.createRecord('member', {
|
2020-06-05 10:49:56 +03:00
|
|
|
email: user.get('email'),
|
2022-04-26 10:32:21 +03:00
|
|
|
name: user.get('name'),
|
|
|
|
newsletters: defaultNewsletters
|
2019-12-03 08:04:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
2020-06-05 10:49:56 +03:00
|
|
|
yield member.save();
|
|
|
|
|
|
|
|
if (this.args.afterCreate) {
|
|
|
|
this.args.afterCreate();
|
|
|
|
}
|
|
|
|
|
2021-07-15 17:27:29 +03:00
|
|
|
this.notifications.showNotification('Member added',
|
2020-02-27 12:19:29 +03:00
|
|
|
{
|
2024-05-14 10:31:19 +03:00
|
|
|
description: 'You\'ve added yourself as a member.'
|
2020-02-27 12:19:29 +03:00
|
|
|
}
|
|
|
|
);
|
2019-12-03 08:04:04 +03:00
|
|
|
|
2024-01-31 00:08:27 +03:00
|
|
|
// force update the member count; this otherwise only updates every minute
|
|
|
|
yield this.membersCountCache.count({});
|
2024-05-14 10:31:19 +03:00
|
|
|
|
2020-06-05 10:49:56 +03:00
|
|
|
return member;
|
2019-12-03 08:04:04 +03:00
|
|
|
} catch (error) {
|
|
|
|
if (error) {
|
|
|
|
this.notifications.showAPIError(error, {key: 'member.save'});
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 10:49:56 +03:00
|
|
|
}
|
|
|
|
}
|