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';
|
2020-06-05 10:49:56 +03:00
|
|
|
import {task} from 'ember-concurrency-decorators';
|
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;
|
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;
|
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'),
|
|
|
|
name: user.get('name')
|
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();
|
|
|
|
}
|
|
|
|
|
2020-02-27 12:19:29 +03:00
|
|
|
this.notifications.showNotification('Member added'.htmlSafe(),
|
|
|
|
{
|
|
|
|
description: 'You\'ve successfully added yourself as a member.'
|
|
|
|
}
|
|
|
|
);
|
2019-12-03 08:04:04 +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
|
|
|
}
|
|
|
|
}
|