mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
upgrade-banners: Refactor upgrade banners.
Instead of defining three separate banner objects with mostly identical properties, dynamically construct the buttons array and intent based on user permissions and organization type. Also changes "Upgrade to access" button text to just "Upgrade" for consistency.
This commit is contained in:
committed by
Tim Abbott
parent
fac28bf800
commit
7732aa0423
@@ -2,54 +2,12 @@ import $ from "jquery";
|
||||
|
||||
import * as banners from "./banners.ts";
|
||||
import type {Banner} from "./banners.ts";
|
||||
import type {ActionButton} from "./buttons.ts";
|
||||
import {$t} from "./i18n.ts";
|
||||
import * as settings_config from "./settings_config.ts";
|
||||
import * as settings_data from "./settings_data.ts";
|
||||
import {realm} from "./state_data.ts";
|
||||
|
||||
const UPGRADE_ACCESS_BANNER: Banner = {
|
||||
intent: "info",
|
||||
label: $t({defaultMessage: "Available on Zulip Cloud Standard."}),
|
||||
buttons: [
|
||||
{
|
||||
label: $t({defaultMessage: "Upgrade to access"}),
|
||||
custom_classes: "request-upgrade",
|
||||
attention: "quiet",
|
||||
},
|
||||
],
|
||||
custom_classes: "organization-upgrade-banner",
|
||||
close_button: false,
|
||||
};
|
||||
|
||||
const AVAILABLE_ON_STANDARD: Banner = {
|
||||
intent: "neutral",
|
||||
label: $t({defaultMessage: "Available on Zulip Cloud Standard."}),
|
||||
buttons: [],
|
||||
custom_classes: "organization-upgrade-banner",
|
||||
close_button: false,
|
||||
};
|
||||
|
||||
const UPGRADE_OR_SPONSORSHIP_BANNER: Banner = {
|
||||
intent: "info",
|
||||
label: $t({
|
||||
defaultMessage: "Available on Zulip Cloud Standard.",
|
||||
}),
|
||||
buttons: [
|
||||
{
|
||||
label: $t({defaultMessage: "Upgrade"}),
|
||||
custom_classes: "request-upgrade",
|
||||
attention: "quiet",
|
||||
},
|
||||
{
|
||||
label: $t({defaultMessage: "Request sponsorship"}),
|
||||
custom_classes: "request-sponsorship",
|
||||
attention: "borderless",
|
||||
},
|
||||
],
|
||||
custom_classes: "organization-upgrade-banner",
|
||||
close_button: false,
|
||||
};
|
||||
|
||||
export function set_up_upgrade_banners(): void {
|
||||
const has_billing_access = settings_data.user_has_billing_access();
|
||||
const is_business_type_org =
|
||||
@@ -60,13 +18,40 @@ export function set_up_upgrade_banners(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
let banner;
|
||||
if (is_business_type_org) {
|
||||
banner = has_billing_access ? UPGRADE_ACCESS_BANNER : AVAILABLE_ON_STANDARD;
|
||||
} else {
|
||||
banner = has_billing_access ? UPGRADE_OR_SPONSORSHIP_BANNER : AVAILABLE_ON_STANDARD;
|
||||
let upgrade_buttons: ActionButton[] = [];
|
||||
let banner_intent: Banner["intent"] = "neutral";
|
||||
|
||||
if (has_billing_access) {
|
||||
banner_intent = "info";
|
||||
upgrade_buttons = [
|
||||
{
|
||||
label: $t({defaultMessage: "Upgrade"}),
|
||||
custom_classes: "request-upgrade",
|
||||
attention: "quiet",
|
||||
},
|
||||
];
|
||||
|
||||
if (!is_business_type_org) {
|
||||
upgrade_buttons = [
|
||||
...upgrade_buttons,
|
||||
{
|
||||
label: $t({defaultMessage: "Request sponsorship"}),
|
||||
custom_classes: "request-sponsorship",
|
||||
attention: "borderless",
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
banners.open(banner, $upgrade_banner_containers);
|
||||
|
||||
const upgrade_banner: Banner = {
|
||||
intent: banner_intent,
|
||||
label: $t({defaultMessage: "Available on Zulip Cloud Standard."}),
|
||||
buttons: upgrade_buttons,
|
||||
custom_classes: "organization-upgrade-banner",
|
||||
close_button: false,
|
||||
};
|
||||
|
||||
banners.open(upgrade_banner, $upgrade_banner_containers);
|
||||
}
|
||||
|
||||
export function set_up_banner($container: JQuery, banner: Banner, url?: string): void {
|
||||
|
Reference in New Issue
Block a user