From cda3da18f4f51117bc166beb828bdc66904607a6 Mon Sep 17 00:00:00 2001 From: Tushar912 Date: Thu, 4 Mar 2021 23:58:02 +0530 Subject: [PATCH] settings: Refactor check_profile_incomplete. Split the logic of check_profile_incomplete into two functions show_profile_incomplete and check_profile_incomplete. The latter is passed to the former which shows the message if the profile is incomplete. --- static/js/panels.js | 15 ++++++++++----- static/js/server_events_dispatch.js | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/static/js/panels.js b/static/js/panels.js index 9dabfa4882..cd04113044 100644 --- a/static/js/panels.js +++ b/static/js/panels.js @@ -50,7 +50,7 @@ function should_show_notifications(ls) { export function check_profile_incomplete() { if (!page_params.is_admin) { - return; + return false; } // Eventually, we might also check page_params.realm_icon_source, @@ -60,6 +60,13 @@ export function check_profile_incomplete() { page_params.realm_description === "" || /^Organization imported from [A-Za-z]+[!.]$/.test(page_params.realm_description) ) { + return true; + } + return false; +} + +export function show_profile_incomplete(is_profile_incomplete) { + if (is_profile_incomplete) { $("[data-process='profile-incomplete']").show(); } else { $("[data-process='profile-incomplete']").hide(); @@ -78,10 +85,8 @@ export function initialize() { open($("[data-process='notifications']")); } else if (unread_ui.should_display_bankruptcy_banner()) { open($("[data-process='bankruptcy']")); - } else { - // TODO: This should be restructured with separate check and - // show calls. - check_profile_incomplete(); + } else if (check_profile_incomplete()) { + open($("[data-process='profile-incomplete']")); } // Configure click handlers. diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index c6441ac230..09dfe53360 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -252,7 +252,7 @@ export function dispatch_normal_event(event) { if (page_params.is_admin) { // Update the UI notice about the user's profile being // incomplete, as we might have filled in the missing field(s). - panels.check_profile_incomplete(); + panels.show_profile_incomplete(panels.check_profile_incomplete()); } break; }