From be6d42d46f23a963a9a8d671f26ced43472e5796 Mon Sep 17 00:00:00 2001 From: Tobias Karlsson Date: Tue, 13 Aug 2019 22:56:24 +0200 Subject: [PATCH] Improve feedback on user deletion Fixes #1750, #1777 --- framework/core/js/src/forum/utils/History.js | 2 +- .../core/js/src/forum/utils/UserControls.js | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/framework/core/js/src/forum/utils/History.js b/framework/core/js/src/forum/utils/History.js index b71b84951..d8b2a89e5 100644 --- a/framework/core/js/src/forum/utils/History.js +++ b/framework/core/js/src/forum/utils/History.js @@ -92,7 +92,7 @@ export default class History { this.stack.pop(); - m.route(this.getCurrent().url); + this.canGoBack() ? m.route(this.getCurrent().url) : this.home(); } /** diff --git a/framework/core/js/src/forum/utils/UserControls.js b/framework/core/js/src/forum/utils/UserControls.js index c588af6df..07fb89090 100644 --- a/framework/core/js/src/forum/utils/UserControls.js +++ b/framework/core/js/src/forum/utils/UserControls.js @@ -1,3 +1,4 @@ +import Alert from '../../common/components/Alert'; import Button from '../../common/components/Button'; import Separator from '../../common/components/Separator'; import EditUserModal from '../components/EditUserModal'; @@ -95,15 +96,29 @@ export default { * Delete the user. */ deleteAction() { - if (confirm(app.translator.trans('core.forum.user_controls.delete_confirmation'))) { - this.delete().then(() => { - if (app.current instanceof UserPage && app.current.user === this) { - app.history.back(); - } else { - window.location.reload(); - } - }); + if (!confirm(app.translator.trans('core.forum.user_controls.delete_confirmation'))) { + return; } + + const showAlert = type => { + const { username, email } = this.data.attributes; + + app.alerts.show(new Alert({ + type, + children: app.translator.trans( + `core.forum.user.delete_alert_${type}`, { username, email } + ) + })); + }; + + this.delete().then(() => { + showAlert('success'); + if (app.current instanceof UserPage && app.current.user === this) { + app.history.back(); + } else { + window.location.reload(); + } + }).catch(() => showAlert('error')); }, /**