diff --git a/ui/core/app/routes/scopes/scope/groups.js b/ui/core/app/routes/scopes/scope/groups.js index 1d04d7bb5..38085bfc7 100644 --- a/ui/core/app/routes/scopes/scope/groups.js +++ b/ui/core/app/routes/scopes/scope/groups.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import loading from 'ember-loading/decorator'; import { confirm } from '../../../decorators/confirm'; +import { notifySuccess, notifyError } from '../../../decorators/notify'; export default class ScopesScopeGroupsRoute extends Route { // =services @@ -47,20 +48,12 @@ export default class ScopesScopeGroupsRoute extends Route { */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(group) { - const { isNew } = group; - try { - await group.save(); - await this.transitionTo('scopes.scope.groups.group', group); - this.refresh(); - this.notify.success( - this.intl.t(isNew ? 'notifications.create-success' : 'notifications.save-success') - ); - } catch (error) { - //TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - throw error; - } + await group.save(); + await this.transitionTo('scopes.scope.groups.group', group); + this.refresh(); } /** @@ -70,15 +63,11 @@ export default class ScopesScopeGroupsRoute extends Route { @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async delete(group) { - try { - await group.destroyRecord(); - await this.replaceWith('scopes.scope.groups'); - this.refresh(); - this.notify.success(this.intl.t('notifications.delete-success')); - } catch (error) { - //TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await group.destroyRecord(); + await this.replaceWith('scopes.scope.groups'); + this.refresh(); } } diff --git a/ui/core/app/routes/scopes/scope/groups/group/add-members.js b/ui/core/app/routes/scopes/scope/groups/group/add-members.js index 240e0a442..d4f392684 100644 --- a/ui/core/app/routes/scopes/scope/groups/group/add-members.js +++ b/ui/core/app/routes/scopes/scope/groups/group/add-members.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { hash } from 'rsvp'; import loading from 'ember-loading/decorator'; +import { notifySuccess, notifyError } from '../../../../../decorators/notify'; export default class ScopesScopeGroupsGroupAddMembersRoute extends Route { // =services @@ -65,15 +66,11 @@ export default class ScopesScopeGroupsGroupAddMembersRoute extends Route { */ @action @loading + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.add-success') async addMembers(group, userIDs) { - try { - await group.addMembers(userIDs); - await this.replaceWith('scopes.scope.groups.group.members'); - this.notify.success(this.intl.t('notifications.add-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await group.addMembers(userIDs); + await this.replaceWith('scopes.scope.groups.group.members'); } /** diff --git a/ui/core/app/routes/scopes/scope/groups/group/members.js b/ui/core/app/routes/scopes/scope/groups/group/members.js index 4cf76322c..be4f97343 100644 --- a/ui/core/app/routes/scopes/scope/groups/group/members.js +++ b/ui/core/app/routes/scopes/scope/groups/group/members.js @@ -4,6 +4,7 @@ import { inject as service } from '@ember/service'; import { hash, all } from 'rsvp'; import loading from 'ember-loading/decorator'; import { confirm } from '../../../../../decorators/confirm'; +import { notifySuccess, notifyError } from '../../../../../decorators/notify'; export default class ScopesScopeGroupsGroupMembersRoute extends Route { // =services @@ -40,14 +41,10 @@ export default class ScopesScopeGroupsGroupMembersRoute extends Route { @action @loading @confirm('questions.remove-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.remove-success') async removeMember(group, member) { - try { - await group.removeMember(member.id); - this.refresh(); - this.notify.success(this.intl.t('notifications.remove-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await group.removeMember(member.id); + this.refresh(); } }