From 2a9145c212868763d6fa44403ad772d64d79e6d3 Mon Sep 17 00:00:00 2001 From: Yogesh Sirsat Date: Sun, 11 Sep 2022 18:44:06 +0530 Subject: [PATCH] user_profile: Initialize user type fields only when necessary. --- static/js/user_profile.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/static/js/user_profile.js b/static/js/user_profile.js index 2e857d13f0..cbd840e011 100644 --- a/static/js/user_profile.js +++ b/static/js/user_profile.js @@ -160,6 +160,21 @@ export function hide_user_profile() { overlays.close_modal("user-profile-modal"); } +function initialize_user_type_fields(user) { + // Avoid duplicate pill fields, by removing existing ones. + $("#user-profile-modal .pill").remove(); + if (!user.is_bot) { + settings_account.initialize_custom_user_type_fields( + "#user-profile-modal #content", + user.user_id, + false, + false, + ); + } else { + initialize_bot_owner("#user-profile-modal #content", user.user_id); + } +} + export function show_user_profile(user, default_tab_key = "profile-tab") { popovers.hide_all(); @@ -223,6 +238,9 @@ export function show_user_profile(user, default_tab_key = "profile-tab") { $(".tabcontent").hide(); $("#" + key).show(); switch (key) { + case "profile-tab": + initialize_user_type_fields(user); + break; case "user-profile-groups-tab": render_user_group_list(groups_of_user, user); break; @@ -236,17 +254,6 @@ export function show_user_profile(user, default_tab_key = "profile-tab") { const $elem = components.toggle(opts).get(); $elem.addClass("large allow-overflow"); $("#tab-toggle").append($elem); - - if (!user.is_bot) { - settings_account.initialize_custom_user_type_fields( - "#user-profile-modal #content", - user.user_id, - false, - false, - ); - } else { - initialize_bot_owner("#user-profile-modal #content", user.user_id); - } } function handle_remove_stream_subscription(target_user_id, sub, success, failure) {