2019-12-03 08:04:04 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
session: service(),
|
|
|
|
store: service(),
|
|
|
|
notifications: service(),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
addYourself() {
|
|
|
|
return this.add.perform();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
add: task(function* () {
|
|
|
|
const member = this.store.createRecord('member', {
|
|
|
|
email: this.get('session.user.email'),
|
|
|
|
name: this.get('session.user.name')
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
// NOTE: has to be before member.save() is performed otherwise component is
|
|
|
|
// destroyed before notification is shown
|
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
|
|
|
|
|
|
|
return yield member.save();
|
|
|
|
} catch (error) {
|
|
|
|
if (error) {
|
|
|
|
this.notifications.showAPIError(error, {key: 'member.save'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).drop()
|
|
|
|
});
|