mirror of
https://github.com/flarum/framework.git
synced 2025-02-08 20:31:44 +08:00
Fix errors caused by deletion alert when deleting users (#1883)
Refs #1788 TypeError: t.showDeletionAlert is not a function at onSuccess(./src/forum/utils/UserControls.js:104:12) Also, don't override 'this' param with user object for editAction
This commit is contained in:
parent
e0c2ef5e64
commit
1dd329982a
|
@ -62,7 +62,7 @@ export default {
|
||||||
items.add('edit', Button.component({
|
items.add('edit', Button.component({
|
||||||
icon: 'fas fa-pencil-alt',
|
icon: 'fas fa-pencil-alt',
|
||||||
children: app.translator.trans('core.forum.user_controls.edit_button'),
|
children: app.translator.trans('core.forum.user_controls.edit_button'),
|
||||||
onclick: this.editAction.bind(user)
|
onclick: this.editAction.bind(this, user)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ export default {
|
||||||
items.add('delete', Button.component({
|
items.add('delete', Button.component({
|
||||||
icon: 'fas fa-times',
|
icon: 'fas fa-times',
|
||||||
children: app.translator.trans('core.forum.user_controls.delete_button'),
|
children: app.translator.trans('core.forum.user_controls.delete_button'),
|
||||||
onclick: this.deleteAction.bind(user)
|
onclick: this.deleteAction.bind(this, user)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,24 +94,32 @@ export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the user.
|
* Delete the user.
|
||||||
|
*
|
||||||
|
* @param {User} user
|
||||||
*/
|
*/
|
||||||
deleteAction() {
|
deleteAction(user) {
|
||||||
if (!confirm(app.translator.trans('core.forum.user_controls.delete_confirmation'))) {
|
if (!confirm(app.translator.trans('core.forum.user_controls.delete_confirmation'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.delete().then(() => {
|
user.delete().then(() => {
|
||||||
this.showDeletionAlert('success');
|
this.showDeletionAlert(user, 'success');
|
||||||
if (app.current instanceof UserPage && app.current.user === this) {
|
if (app.current instanceof UserPage && app.current.user === user) {
|
||||||
app.history.back();
|
app.history.back();
|
||||||
} else {
|
} else {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}).catch(() => this.showDeletionAlert('error'));
|
}).catch(() => this.showDeletionAlert(user, 'error'));
|
||||||
},
|
},
|
||||||
|
|
||||||
showDeletionAlert(type) {
|
/**
|
||||||
const { username, email } = this.data.attributes;
|
* Show deletion alert of user.
|
||||||
|
*
|
||||||
|
* @param {User} user
|
||||||
|
* @param {string} type
|
||||||
|
*/
|
||||||
|
showDeletionAlert(user, type) {
|
||||||
|
const { username, email } = user.data.attributes;
|
||||||
const message = {
|
const message = {
|
||||||
success: 'core.forum.user_controls.delete_success_message',
|
success: 'core.forum.user_controls.delete_success_message',
|
||||||
error: 'core.forum.user_controls.delete_error_message',
|
error: 'core.forum.user_controls.delete_error_message',
|
||||||
|
@ -127,8 +135,10 @@ export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit the user.
|
* Edit the user.
|
||||||
|
*
|
||||||
|
* @param {User} user
|
||||||
*/
|
*/
|
||||||
editAction() {
|
editAction(user) {
|
||||||
app.modal.show(new EditUserModal({user: this}));
|
app.modal.show(new EditUserModal({ user }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user