settings: Pass handle_confirm function as argument to confirm_deactivation.

We pass handle_confirm function as an argument to confirm_deactivation
because we will use confirm_deactivation to deactivate the user from
user-info popover and the popover case will have a different handle_confirm
function (which is called after clicking "Confirm" button of the modal)
since error handling in that case will be different as there will be no
overlay in the background.
This commit is contained in:
Sahil Batra 2021-11-29 17:41:56 +05:30 committed by Tim Abbott
parent 1490c91011
commit 0a27c38af7
1 changed files with 19 additions and 18 deletions

View File

@ -424,7 +424,7 @@ function get_human_profile_data(fields_user_pills) {
return new_profile_data; return new_profile_data;
} }
function confirm_deactivation(row, user_id, status_field) { function confirm_deactivation(user_id, handle_confirm) {
const user = people.get_by_user_id(user_id); const user = people.get_by_user_id(user_id);
const opts = { const opts = {
username: user.full_name, username: user.full_name,
@ -432,22 +432,6 @@ function confirm_deactivation(row, user_id, status_field) {
}; };
const html_body = render_settings_deactivation_user_modal(opts); const html_body = render_settings_deactivation_user_modal(opts);
function handle_confirm() {
const row = get_user_info_row(user_id);
const row_deactivate_button = row.find("button.deactivate");
row_deactivate_button.prop("disabled", true).text($t({defaultMessage: "Working…"}));
const opts = {
success_continuation() {
update_view_on_deactivate(row);
},
error_continuation() {
row_deactivate_button.text($t({defaultMessage: "Deactivate"}));
},
};
const url = "/json/users/" + encodeURIComponent(user_id);
settings_ui.do_settings_change(channel.del, url, {}, status_field, opts);
}
confirm_dialog.launch({ confirm_dialog.launch({
html_heading: $t_html({defaultMessage: "Deactivate {name}"}, {name: user.full_name}), html_heading: $t_html({defaultMessage: "Deactivate {name}"}, {name: user.full_name}),
html_body, html_body,
@ -464,7 +448,24 @@ function handle_deactivation(tbody, status_field) {
const row = $(e.target).closest(".user_row"); const row = $(e.target).closest(".user_row");
const user_id = row.data("user-id"); const user_id = row.data("user-id");
confirm_deactivation(row, user_id, status_field);
function handle_confirm() {
const row = get_user_info_row(user_id);
const row_deactivate_button = row.find("button.deactivate");
row_deactivate_button.prop("disabled", true).text($t({defaultMessage: "Working…"}));
const opts = {
success_continuation() {
update_view_on_deactivate(row);
},
error_continuation() {
row_deactivate_button.text($t({defaultMessage: "Deactivate"}));
},
};
const url = "/json/users/" + encodeURIComponent(user_id);
settings_ui.do_settings_change(channel.del, url, {}, status_field, opts);
}
confirm_deactivation(user_id, handle_confirm);
}); });
} }