diff --git a/ui/core/app/routes/scopes/scope/projects/project/targets.js b/ui/core/app/routes/scopes/scope/projects/project/targets.js index b2670942c..68e0b98d0 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/targets.js +++ b/ui/core/app/routes/scopes/scope/projects/project/targets.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 ScopesScopeProjectsProjectTargetsRoute extends Route { // =services @@ -41,20 +42,12 @@ export default class ScopesScopeProjectsProjectTargetsRoute extends Route { */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(target) { - const { isNew } = target; - try { - await target.save(); - await this.transitionTo('scopes.scope.projects.project.targets.target', target); - 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 target.save(); + await this.transitionTo('scopes.scope.projects.project.targets.target', target); + this.refresh(); } /** @@ -64,15 +57,11 @@ export default class ScopesScopeProjectsProjectTargetsRoute extends Route { @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async delete(target) { - try { - await target.destroyRecord(); - await this.replaceWith('scopes.scope.projects.project.targets'); - 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 target.destroyRecord(); + await this.replaceWith('scopes.scope.projects.project.targets'); + this.refresh(); } } diff --git a/ui/core/app/routes/scopes/scope/projects/project/targets/target/add-host-sets.js b/ui/core/app/routes/scopes/scope/projects/project/targets/target/add-host-sets.js index 5736ae317..b747fda00 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/targets/target/add-host-sets.js +++ b/ui/core/app/routes/scopes/scope/projects/project/targets/target/add-host-sets.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 ScopesScopeProjectsProjectTargetsTargetAddHostSetsRoute extends Route { // =services @@ -72,17 +73,13 @@ export default class ScopesScopeProjectsProjectTargetsTargetAddHostSetsRoute ext @action @loading + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.add-success') async save(target, hostSetIDs) { - try { - await target.addHostSets(hostSetIDs); - this.replaceWith( - 'scopes.scope.projects.project.targets.target.host-sets' - ); - this.notify.success(this.intl.t('notifications.add-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await target.addHostSets(hostSetIDs); + this.replaceWith( + 'scopes.scope.projects.project.targets.target.host-sets' + ); } /** diff --git a/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js b/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js index dd9e52f0e..08d839f1f 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js +++ b/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js @@ -4,6 +4,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 ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extends Route { // =services @@ -57,14 +58,10 @@ export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extend @action @loading @confirm('questions.remove-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.remove-success') async removeHostSet(target, hostSet) { - try { - await target.removeHostSet(hostSet.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 target.removeHostSet(hostSet.id); + this.refresh(); } }