Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

navbar_alerts: Add alerts for demo org deadlines.

Eeshan Garg9c501f3efc28
diff --git a/frontend_tests/node_tests/navbar_alerts.js b/frontend_tests/node_tests/navbar_alerts.js
index f7d4c615076..a6facc7d386 100644
--- a/frontend_tests/node_tests/navbar_alerts.js
+++ b/frontend_tests/node_tests/navbar_alerts.js
@@ -116,3 +116,21 @@ test("server_upgrade_alert hide_duration_expired", ({override}) => {
navbar_alerts.dismiss_upgrade_nag(ls);
assert.equal(navbar_alerts.should_show_server_upgrade_notification(ls), false);
});
+
+test("demo_org_days_remaining", ({override}) => {
+ const start_time = new Date(1620327447050); // Thursday 06/5/2021 07:02:27 AM (UTC+0)
+
+ const high_priority_deadline = addDays(start_time, 5);
+ page_params.demo_organization_scheduled_deletion_date = Math.trunc(
+ high_priority_deadline / 1000,
+ );
+ override(Date, "now", () => start_time);
+ assert.equal(navbar_alerts.get_demo_organization_deadline_days_remaining(), 5);
+
+ const low_priority_deadline = addDays(start_time, 10);
+ page_params.demo_organization_scheduled_deletion_date = Math.trunc(
+ low_priority_deadline / 1000,
+ );
+ override(Date, "now", () => start_time);
+ assert.equal(navbar_alerts.get_demo_organization_deadline_days_remaining(), 10);
+});
diff --git a/static/js/navbar_alerts.js b/static/js/navbar_alerts.js
index 6f9349e3d42..4da07ca95e6 100644
--- a/static/js/navbar_alerts.js
+++ b/static/js/navbar_alerts.js
@@ -3,6 +3,7 @@ import $ from "jquery";
import render_bankruptcy_alert_content from "../templates/navbar_alerts/bankruptcy.hbs";
import render_configure_email_alert_content from "../templates/navbar_alerts/configure_outgoing_email.hbs";
+import render_demo_organization_deadline_content from "../templates/navbar_alerts/demo_organization_deadline.hbs";
import render_desktop_notifications_alert_content from "../templates/navbar_alerts/desktop_notifications.hbs";
import render_insecure_desktop_app_alert_content from "../templates/navbar_alerts/insecure_desktop_app.hbs";
import render_navbar_alert_wrapper from "../templates/navbar_alerts/navbar_alert_wrapper.hbs";
@@ -122,9 +123,27 @@ export function show_profile_incomplete(is_profile_incomplete) {
}
}
+export function get_demo_organization_deadline_days_remaining() {
+ const now = new Date(Date.now());
+ const deadline = new Date(page_params.demo_organization_scheduled_deletion_date * 1000);
+ const day = 24 * 60 * 60 * 1000; // hours * minutes * seconds * milliseconds
+ const days_remaining = Math.round(Math.abs(deadline - now) / day);
+ return days_remaining;
+}
+
export function initialize() {
const ls = localstorage();
- if (page_params.insecure_desktop_app) {
+
+ if (page_params.demo_organization_scheduled_deletion_date) {
+ const days_remaining = get_demo_organization_deadline_days_remaining();
+ open({
+ data_process: "demo-organization-deadline",
+ custom_class: days_remaining <= 7 ? "red" : "",
+ rendered_alert_content_html: render_demo_organization_deadline_content({
+ days_remaining,
+ }),
+ });
+ } else if (page_params.insecure_desktop_app) {
open({
data_process: "insecure-desktop-app",
custom_class: "red",
@@ -179,6 +198,11 @@ export function initialize() {
$(window).trigger("resize");
});
+ $(".hide-demo-org-notice").on("click", function () {
+ $(this).closest(".alert").hide();
+ $(window).trigger("resize");
+ });
+
$(".accept-bankruptcy").on("click", function (e) {
e.preventDefault();
const $process = $(this).closest("[data-process]");
diff --git a/static/templates/navbar_alerts/demo_organization_deadline.hbs b/static/templates/navbar_alerts/demo_organization_deadline.hbs
new file mode 100644
index 00000000000..cdeafc6ef37
--- /dev/null
+++ b/static/templates/navbar_alerts/demo_organization_deadline.hbs
@@ -0,0 +1,7 @@
+<div data-step="1">
+ {{#tr}}
+ This is a <z-link>demo organization</z-link> and will be automatically deleted in {days_remaining} days.
+ {{#*inline "z-link"}}<a class="alert-link" href="/help/demo-organizations" target="_blank" rel="noopener noreferrer" role="button" tabindex=0>{{> @partial-block}}</a>{{/inline}}
+ {{/tr}}
+ <a class="alert-link hide-demo-org-notice" role="button" tabindex=0>{{t "Hide notice" }}</a>
+</div>