From 0ef7be5e5854f9b29f0e4e042e0a0e7fdc74b5a3 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 8 Oct 2020 18:11:48 -0400 Subject: [PATCH] feat: Update auth method route for notify decorator --- .../app/routes/scopes/scope/auth-methods.js | 39 +++++++------------ .../auth-methods/auth-method/accounts.js | 38 +++++++----------- .../accounts/account/set-password.js | 17 ++++---- 3 files changed, 35 insertions(+), 59 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/auth-methods.js b/ui/core/app/routes/scopes/scope/auth-methods.js index c91387c71..020ed8b9f 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods.js +++ b/ui/core/app/routes/scopes/scope/auth-methods.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 ScopesScopeAuthMethodsRoute extends Route { // =services @@ -47,23 +48,15 @@ export default class ScopesScopeAuthMethodsRoute extends Route { */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(authMethod) { - const { isNew } = authMethod; - try { - await authMethod.save(); - await this.transitionTo( - 'scopes.scope.auth-methods.auth-method', - authMethod - ); - 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 authMethod.save(); + await this.transitionTo( + 'scopes.scope.auth-methods.auth-method', + authMethod + ); + this.refresh(); } /** @@ -73,15 +66,11 @@ export default class ScopesScopeAuthMethodsRoute extends Route { @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async delete(authMethod) { - try { - await authMethod.destroyRecord(); - await this.replaceWith('scopes.scope.auth-methods'); - 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 authMethod.destroyRecord(); + await this.replaceWith('scopes.scope.auth-methods'); + this.refresh(); } } diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js index 93cbefd58..94871fd6f 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js @@ -3,6 +3,7 @@ import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import loading from 'ember-loading/decorator'; import { confirm } from '../../../../../decorators/confirm'; +import { notifySuccess, notifyError } from '../../../../../decorators/notify'; export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route { // =services @@ -43,27 +44,20 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(account, password) { const { isNew } = account; const adapterOptions = {}; if (isNew) { adapterOptions.password = password; } - try { - await account.save({ adapterOptions }); - await this.transitionTo( - 'scopes.scope.auth-methods.auth-method.accounts.account', - account - ); - 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 account.save({ adapterOptions }); + await this.transitionTo( + 'scopes.scope.auth-methods.auth-method.accounts.account', + account + ); + this.refresh(); } /** @@ -73,15 +67,11 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async deleteAccount(account) { - try { - await account.destroyRecord(); - await this.replaceWith('scopes.scope.auth-methods.auth-method.accounts'); - 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 account.destroyRecord(); + await this.replaceWith('scopes.scope.auth-methods.auth-method.accounts'); + this.refresh(); } } diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/set-password.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/set-password.js index 900c5eaba..2f5886030 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/set-password.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/set-password.js @@ -2,6 +2,7 @@ import Route from '@ember/routing/route'; import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import loading from 'ember-loading/decorator'; +import { notifySuccess, notifyError } from '../../../../../../../decorators/notify'; export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRoute extends Route { // =services @@ -35,16 +36,12 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout */ @action @loading + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.save-success') async setPassword(account, password) { - try { - await account.setPassword(password); - await this.replaceWith( - 'scopes.scope.auth-methods.auth-method.accounts.account.set-password' - ); - this.notify.success(this.intl.t('notifications.save-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await account.setPassword(password); + await this.replaceWith( + 'scopes.scope.auth-methods.auth-method.accounts.account.set-password' + ); } }