feat: Update auth method route for notify decorator
This commit is contained in:
3 files changed
+35
-59
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 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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
+7
-10
@@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user