From cec8191bfac79eab3e344ecf85ccf58f6d5322af Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Mon, 29 Nov 2021 18:50:23 +0530 Subject: [PATCH] popovers: Add option to deactivate user to "Manage user" modal. This commit adds option to deactivate user to "Manage user" modal. A modal is opened on clicking the option to confirm the deactivation and the "Manage user" modal is closed. The error from the server, if any, is shown in the modal itself and in case deactivation is done successfully, the modal is closed. Fixes #18944. --- static/js/settings_users.js | 35 +++++++++++++++++-- .../templates/settings/admin_human_form.hbs | 5 +++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 7a7eba6253..9e587be200 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -424,7 +424,7 @@ function get_human_profile_data(fields_user_pills) { return new_profile_data; } -function confirm_deactivation(user_id, handle_confirm) { +export function confirm_deactivation(user_id, handle_confirm, loading_spinner) { const user = people.get_by_user_id(user_id); const opts = { username: user.full_name, @@ -436,6 +436,7 @@ function confirm_deactivation(user_id, handle_confirm) { html_heading: $t_html({defaultMessage: "Deactivate {name}"}, {name: user.full_name}), html_body, on_click: handle_confirm, + loading_spinner, }); } @@ -465,7 +466,7 @@ function handle_deactivation(tbody, status_field) { settings_ui.do_settings_change(channel.del, url, {}, status_field, opts); } - confirm_deactivation(user_id, handle_confirm); + confirm_deactivation(user_id, handle_confirm, false); }); } @@ -560,6 +561,36 @@ export function show_edit_user_info_modal(user_id, from_user_info_popover, statu true, false, ); + + $("#edit-user-form").on("click", ".deactivate_user_button", (e) => { + e.preventDefault(); + e.stopPropagation(); + const user_id = $("#edit-user-form").data("user-id"); + function handle_confirm() { + const url = "/json/users/" + encodeURIComponent(user_id); + channel.del({ + url, + success() { + dialog_widget.close_modal(); + if (!from_user_info_popover) { + const row = get_user_info_row(user_id); + update_view_on_deactivate(row); + } + }, + error(xhr) { + ui_report.error( + $t_html({defaultMessage: "Failed"}), + xhr, + $("#dialog_error"), + ); + dialog_widget.hide_dialog_spinner(); + }, + }); + } + const open_deactivate_modal_callback = () => + confirm_deactivation(user_id, handle_confirm, true); + dialog_widget.close_modal(open_deactivate_modal_callback); + }); } function submit_user_details() { diff --git a/static/templates/settings/admin_human_form.hbs b/static/templates/settings/admin_human_form.hbs index 1d7b26ce4c..d3811e88be 100644 --- a/static/templates/settings/admin_human_form.hbs +++ b/static/templates/settings/admin_human_form.hbs @@ -22,5 +22,10 @@
+
+ +