From ea80791b96ce9c9de9306cc51c3e07532920f38c Mon Sep 17 00:00:00 2001 From: afeefuddin Date: Sat, 2 Nov 2024 02:15:57 +0530 Subject: [PATCH] demo_organizations_ui: Convert module to TypeScript. --- tools/test-js-with-node | 2 +- ...zations_ui.js => demo_organizations_ui.ts} | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) rename web/src/{demo_organizations_ui.js => demo_organizations_ui.ts} (83%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 7184560081..148ae37f49 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -94,7 +94,7 @@ EXEMPT_FILES = make_set( "web/src/css_variables.js", "web/src/custom_profile_fields_ui.ts", "web/src/debug.ts", - "web/src/demo_organizations_ui.js", + "web/src/demo_organizations_ui.ts", "web/src/deprecated_feature_notice.ts", "web/src/desktop_integration.js", "web/src/desktop_notifications.ts", diff --git a/web/src/demo_organizations_ui.js b/web/src/demo_organizations_ui.ts similarity index 83% rename from web/src/demo_organizations_ui.js rename to web/src/demo_organizations_ui.ts index 5bf20ad7eb..5412dcf0c2 100644 --- a/web/src/demo_organizations_ui.js +++ b/web/src/demo_organizations_ui.ts @@ -1,4 +1,5 @@ import $ from "jquery"; +import {z} from "zod"; import render_convert_demo_organization_form from "../templates/settings/convert_demo_organization_form.hbs"; import render_demo_organization_warning from "../templates/settings/demo_organization_warning.hbs"; @@ -11,9 +12,11 @@ import {get_demo_organization_deadline_days_remaining} from "./navbar_alerts"; import * as settings_config from "./settings_config"; import * as settings_data from "./settings_data"; import * as settings_org from "./settings_org"; +import type {RequestOpts} from "./settings_ui"; import {current_user, realm} from "./state_data"; +import type {HTMLSelectOneElement} from "./types"; -export function insert_demo_organization_warning() { +export function insert_demo_organization_warning(): void { const days_remaining = get_demo_organization_deadline_days_remaining(); const rendered_demo_organization_warning = render_demo_organization_warning({ is_demo_organization: realm.demo_organization_scheduled_deletion_date, @@ -23,7 +26,7 @@ export function insert_demo_organization_warning() { $(".organization-box").find(".settings-section").prepend($(rendered_demo_organization_warning)); } -export function handle_demo_organization_conversion() { +export function handle_demo_organization_conversion(): void { $(".convert-demo-organization-button").on("click", () => { if (!current_user.is_owner) { return; @@ -39,7 +42,7 @@ export function handle_demo_organization_conversion() { realm_org_type_values: settings_org.get_org_type_dropdown_options(), }); - function demo_organization_conversion_post_render() { + function demo_organization_conversion_post_render(): void { const $convert_submit_button = $( "#demo-organization-conversion-modal .dialog_submit_button", ); @@ -53,8 +56,10 @@ export function handle_demo_organization_conversion() { } else { // Disable submit button if either form field blank. $("#convert-demo-organization-form").on("input change", () => { - const string_id = $("#new_subdomain").val().trim(); - const org_type = $("#add_organization_type").val(); + const string_id = $("input#new_subdomain").val()!.trim(); + const org_type = $( + "select:not([multiple])#add_organization_type", + ).val()!; $convert_submit_button.prop( "disabled", string_id === "" || @@ -65,15 +70,16 @@ export function handle_demo_organization_conversion() { } } - function submit_subdomain() { + function submit_subdomain(): void { const $string_id = $("#new_subdomain"); const $organization_type = $("#add_organization_type"); const data = { string_id: $string_id.val(), org_type: $organization_type.val(), }; - const opts = { - success_continuation(data) { + const opts: RequestOpts = { + success_continuation(raw_data) { + const data = z.object({realm_url: z.string()}).parse(raw_data); window.location.href = data.realm_url; }, };