diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 98be77cdf5..33b7769817 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -890,12 +890,12 @@ run_test('misc', () => { assert.equal(stream_id, 42); return { name: 'some_stream' }; }; - settings_org.render_notifications_stream_ui(42, elem); + settings_org.render_notifications_stream_ui(42, "notifications"); assert.equal(elem.text(), '#some_stream'); assert(!elem.hasClass('text-warning')); stream_data.get_sub_by_id = noop; - settings_org.render_notifications_stream_ui(undefined, elem); + settings_org.render_notifications_stream_ui(undefined, "notifications"); assert.equal(elem.text(), 'translated: Disabled'); assert(elem.hasClass('text-warning')); @@ -907,12 +907,12 @@ run_test('misc', () => { assert.equal(stream_id, 75); return { name: 'some_stream' }; }; - settings_org.render_notifications_stream_ui(75, elem); + settings_org.render_notifications_stream_ui(75, "signup_notifications"); assert.equal(elem.text(), '#some_stream'); assert(!elem.hasClass('text-warning')); stream_data.get_sub_by_id = noop; - settings_org.render_notifications_stream_ui(undefined, elem); + settings_org.render_notifications_stream_ui(undefined, "signup_notifications"); assert.equal(elem.text(), 'translated: Disabled'); assert(elem.hasClass('text-warning')); diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 5f05a571b3..ecf04f77e4 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -142,12 +142,10 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { } } else if (event.property === 'notifications_stream_id') { settings_org.render_notifications_stream_ui( - page_params.realm_notifications_stream_id, - $('#realm_notifications_stream_name')); + page_params.realm_notifications_stream_id, 'notifications'); } else if (event.property === 'signup_notifications_stream_id') { settings_org.render_notifications_stream_ui( - page_params.realm_signup_notifications_stream_id, - $('#realm_signup_notifications_stream_name')); + page_params.realm_signup_notifications_stream_id, 'signup_notifications'); } if (event.property === 'name' && window.electron_bridge !== undefined) { @@ -293,14 +291,12 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { if (page_params.realm_notifications_stream_id === stream.stream_id) { page_params.realm_notifications_stream_id = -1; settings_org.render_notifications_stream_ui( - page_params.realm_notifications_stream_id, - $('#realm_notifications_stream_name')); + page_params.realm_notifications_stream_id, 'notifications'); } if (page_params.realm_signup_notifications_stream_id === stream.stream_id) { page_params.realm_signup_notifications_stream_id = -1; settings_org.render_notifications_stream_ui( - page_params.realm_signup_notifications_stream_id, - $('#realm_signup_notifications_stream_name')); + page_params.realm_signup_notifications_stream_id, 'signup_notifications'); } }); } diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 0df78fe67f..3e6f47587f 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -407,10 +407,13 @@ function insert_tip_box() { .prepend(tip_box); } -exports.render_notifications_stream_ui = function (stream_id, elem) { - +exports.render_notifications_stream_ui = function (stream_id, notification_type) { const name = stream_data.maybe_get_stream_name(stream_id); + $(`#id_realm_${notification_type}_stream`).data("stream-id", stream_id); + + const elem = $(`#realm_${notification_type}_stream_name`); + if (!name) { elem.text(i18n.t("Disabled")); elem.addClass("text-warning"); @@ -628,10 +631,8 @@ exports.build_page = function () { exports.populate_notifications_stream_dropdown(streams); exports.populate_signup_notifications_stream_dropdown(streams); } - exports.render_notifications_stream_ui(page_params.realm_notifications_stream_id, - $('#realm_notifications_stream_name')); - exports.render_notifications_stream_ui(page_params.realm_signup_notifications_stream_id, - $('#realm_signup_notifications_stream_name')); + exports.render_notifications_stream_ui(page_params.realm_notifications_stream_id, 'notifications'); + exports.render_notifications_stream_ui(page_params.realm_signup_notifications_stream_id, 'signup_notifications'); // Populate realm domains exports.populate_realm_domains(page_params.realm_domains); @@ -1069,8 +1070,7 @@ exports.build_page = function () { }); function notification_stream_update(stream_id, notification_type) { - exports.render_notifications_stream_ui(stream_id, - $(`#realm_${notification_type}_stream_name`)); + exports.render_notifications_stream_ui(stream_id, notification_type); exports.save_organization_settings({ [`${notification_type}_stream_id`]: JSON.stringify(parseInt(stream_id, 10)), }, $("#org-submit-notifications"));