-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
manage-roles.js
115 lines (106 loc) · 3.36 KB
/
manage-roles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { tracked } from '@glimmer/tracking';
import classic from 'ember-classic-decorator';
import { classNames } from '@ember-decorators/component';
import { action, computed } from '@ember/object';
import Component from '@ember/component';
import { inject as service } from '@ember/service';
@classic
@classNames('ui', 'fluid', 'card')
export default class ManageRoles extends Component {
@tracked roleType = 'accepted';
@service errorHandler;
@computed('data.roleInvites.@each', 'roleType')
get roleInvites() {
return this.data.roleInvites.filterBy('status', this.roleType);
}
@action
openAddUserRoleModal() {
const currentInvite = this.data.roleInvites.createRecord({});
this.set('currentInvite', currentInvite);
this.set('isAddUserRoleModalOpen', true);
}
@action
addUserRoles() {
this.set('isLoading', true);
this.currentInvite.set('roleName', this.currentInvite.get('role.name'));
this.currentInvite.save()
.then(() => {
this.data.roleInvites.addObject(this.currentInvite);
this.set('isAddUserRoleModalOpen', false);
this.notify.success(this.isNewInvite ? this.l10n.t('Role Invite sent successfully.') : this.l10n.t('Role Invite updated successfully.'), {
id: 'man_role'
});
})
.catch(e => {
console.error('Error while updating role invite', e);
this.errorHandler.handle(e);
})
.finally(() => {
this.set('isLoading', false);
});
}
@action
async resendInvite(invite) {
this.set('isLoading', true);
try {
const res = await this.loader.post('/role-invites/' + invite.id + '/resend-invite');
if (res.success) {
this.notify.success(this.l10n.t('Invite resent successfully.'),
{
id: 'resend_invite_succ'
});
} else {
this.notify.error(this.l10n.t('Oops something went wrong. Please try again.'));
}
} catch (error) {
console.error('Error while resending invite', error);
this.notify.error(this.l10n.t('Oops something went wrong. Please try again.'));
} finally {
this.set('isLoading', false);
}
}
@action
deleteUserRoleInvite(invite) {
this.set('isLoading', true);
invite.destroyRecord()
.then(() => {
this.notify.success(this.l10n.t('Role Invite deleted successfully.'), {
id: 'del_role_succ'
});
this.data.roleInvites.removeObject(invite);
})
.catch(e => {
console.error('Error while deleting role invite', e);
this.notify.error(this.l10n.t('Oops something went wrong. Please try again.'), {
id: 'err_man_role'
});
})
.finally(() => {
this.set('isLoading', false);
});
}
@action
deleteUserRole(eventRole) {
this.set('isLoading', true);
eventRole.destroyRecord()
.then(() => {
this.notify.success(this.l10n.t('Role deleted successfully.'), {
id: 'del_role_succ'
});
this.data.usersEventsRoles.removeObject(eventRole);
})
.catch(e => {
console.error('Error while deleting role', e);
this.notify.error(this.l10n.t('Oops something went wrong. Please try again.'), {
id: 'err_man_role'
});
})
.finally(() => {
this.set('isLoading', false);
});
}
@action
filter(type) {
this.set('roleType', type);
}
}