From 30a64d9e3f6dc59478188efdd6b4e7b0d7875cb4 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 8 Oct 2020 17:24:20 -0400 Subject: [PATCH] feat: Update user account routes to use notify decorator --- .../app/routes/scopes/scope/users/user/accounts.js | 13 +++++-------- .../routes/scopes/scope/users/user/add-accounts.js | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/users/user/accounts.js b/ui/core/app/routes/scopes/scope/users/user/accounts.js index cb00ca24e..4408bdd5c 100644 --- a/ui/core/app/routes/scopes/scope/users/user/accounts.js +++ b/ui/core/app/routes/scopes/scope/users/user/accounts.js @@ -3,6 +3,7 @@ import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import { hash, all } from 'rsvp'; import loading from 'ember-loading/decorator'; +import { notifySuccess, notifyError } from '../../../../../decorators/notify'; export default class ScopesScopeUsersUserAccountsRoute extends Route { // =services @@ -38,14 +39,10 @@ export default class ScopesScopeUsersUserAccountsRoute extends Route { */ @action @loading + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.remove-success') async removeAccount(user, account) { - try { - await user.removeAccount(account.id); - await 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 user.removeAccount(account.id); + await this.refresh(); } } diff --git a/ui/core/app/routes/scopes/scope/users/user/add-accounts.js b/ui/core/app/routes/scopes/scope/users/user/add-accounts.js index bdb7b0e9c..3a1e22f4e 100644 --- a/ui/core/app/routes/scopes/scope/users/user/add-accounts.js +++ b/ui/core/app/routes/scopes/scope/users/user/add-accounts.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { all } from 'rsvp'; import loading from 'ember-loading/decorator'; +import { notifySuccess, notifyError } from '../../../../../decorators/notify'; export default class ScopesScopeUsersUserAddAccountsRoute extends Route { // =services @@ -69,15 +70,11 @@ export default class ScopesScopeUsersUserAddAccountsRoute extends Route { */ @action @loading + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.add-success') async addAccounts(user, accountIDs) { - try { - await user.addAccounts(accountIDs); - await this.replaceWith('scopes.scope.users.user.accounts'); - this.notify.success(this.intl.t('notifications.add-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await user.addAccounts(accountIDs); + await this.replaceWith('scopes.scope.users.user.accounts'); } /**