Merge branch 'refactor-users-route-for-notify-decorator' into feature-notify-decorators
This commit is contained in:
3 files changed
+21
-38
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user