From 82ed8cb70364cb8e9802197c981a3d1dae1c5a55 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 8 Oct 2020 16:37:53 -0400 Subject: [PATCH] feat: Update users route to use notify decorators --- ui/core/app/routes/scopes/scope/users.js | 33 ++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/users.js b/ui/core/app/routes/scopes/scope/users.js index 5cb1f0d4e..d65f2d35f 100644 --- a/ui/core/app/routes/scopes/scope/users.js +++ b/ui/core/app/routes/scopes/scope/users.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 ScopesScopeUsersRoute extends Route { // =services @@ -48,20 +49,12 @@ export default class ScopesScopeUsersRoute extends Route { */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(user) { - const { isNew } = user; - try { - await user.save(); - await this.transitionTo('scopes.scope.users.user', user); - 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 user.save(); + await this.transitionTo('scopes.scope.users.user', user); + this.refresh(); } /** @@ -71,15 +64,11 @@ export default class ScopesScopeUsersRoute extends Route { @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async delete(user) { - try { - await user.destroyRecord(); - await this.replaceWith('scopes.scope.users'); - 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 user.destroyRecord(); + await this.replaceWith('scopes.scope.users'); + this.refresh(); } }