demo_organizations_ui: Convert module to TypeScript.

This commit is contained in:
afeefuddin 2024-11-02 02:15:57 +05:30 committed by Tim Abbott
parent 990c0616d3
commit ea80791b96
2 changed files with 15 additions and 9 deletions

View File

@ -94,7 +94,7 @@ EXEMPT_FILES = make_set(
"web/src/css_variables.js", "web/src/css_variables.js",
"web/src/custom_profile_fields_ui.ts", "web/src/custom_profile_fields_ui.ts",
"web/src/debug.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/deprecated_feature_notice.ts",
"web/src/desktop_integration.js", "web/src/desktop_integration.js",
"web/src/desktop_notifications.ts", "web/src/desktop_notifications.ts",

View File

@ -1,4 +1,5 @@
import $ from "jquery"; import $ from "jquery";
import {z} from "zod";
import render_convert_demo_organization_form from "../templates/settings/convert_demo_organization_form.hbs"; 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"; 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_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import type {RequestOpts} from "./settings_ui";
import {current_user, realm} from "./state_data"; 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 days_remaining = get_demo_organization_deadline_days_remaining();
const rendered_demo_organization_warning = render_demo_organization_warning({ const rendered_demo_organization_warning = render_demo_organization_warning({
is_demo_organization: realm.demo_organization_scheduled_deletion_date, 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)); $(".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", () => { $(".convert-demo-organization-button").on("click", () => {
if (!current_user.is_owner) { if (!current_user.is_owner) {
return; return;
@ -39,7 +42,7 @@ export function handle_demo_organization_conversion() {
realm_org_type_values: settings_org.get_org_type_dropdown_options(), 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 = $( const $convert_submit_button = $(
"#demo-organization-conversion-modal .dialog_submit_button", "#demo-organization-conversion-modal .dialog_submit_button",
); );
@ -53,8 +56,10 @@ export function handle_demo_organization_conversion() {
} else { } else {
// Disable submit button if either form field blank. // Disable submit button if either form field blank.
$("#convert-demo-organization-form").on("input change", () => { $("#convert-demo-organization-form").on("input change", () => {
const string_id = $("#new_subdomain").val().trim(); const string_id = $<HTMLInputElement>("input#new_subdomain").val()!.trim();
const org_type = $("#add_organization_type").val(); const org_type = $<HTMLSelectOneElement>(
"select:not([multiple])#add_organization_type",
).val()!;
$convert_submit_button.prop( $convert_submit_button.prop(
"disabled", "disabled",
string_id === "" || 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 $string_id = $("#new_subdomain");
const $organization_type = $("#add_organization_type"); const $organization_type = $("#add_organization_type");
const data = { const data = {
string_id: $string_id.val(), string_id: $string_id.val(),
org_type: $organization_type.val(), org_type: $organization_type.val(),
}; };
const opts = { const opts: RequestOpts = {
success_continuation(data) { success_continuation(raw_data) {
const data = z.object({realm_url: z.string()}).parse(raw_data);
window.location.href = data.realm_url; window.location.href = data.realm_url;
}, },
}; };