Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
upgrade: Show payment amount based on user input.
Aman Agrawal2f9a48cce7c1
diff --git a/templates/corporate/upgrade.html b/templates/corporate/upgrade.htmlindex 24cad960d98..2036ad36991 100644--- a/templates/corporate/upgrade.html+++ b/templates/corporate/upgrade.html@@ -63,7 +63,7 @@{% endif %}<select name="payment-schedule" id="payment-schedule-select"><option value="monthly" id="autopay_monthly_price"></option>- <option value="annually" id="autopay_annual_price_per_month"></option>+ <option value="annual" id="autopay_annual_price_per_month"></option></select><label for="payment-schedule-select">Payment schedule</label></div>@@ -72,15 +72,22 @@<div class="input-box upgrade-page-field"><label for="licenses" class="inline-block label-title">Number of licenses {% if not exempt_from_license_number_check %}(minimum {{ seat_count }}){% endif %}</label><input type="number" name="licenses" autocomplete="off" {% if not exempt_from_license_number_check %}min="{{ seat_count }}" value="{{ seat_count }}"{% endif %} autocomplete="off" id="manual_license_count" required/>+ <div id="upgrade-licenses-change-error" class="alert alert-danger upgrade-page-error"></div></div>{% endif %}<div class="input-box upgrade-page-field no-validation">- <label for="due_today" class="inline-block label-title">Due today</label>- <div id="due_today" class="not-editable-realm-field">- $6.67 x 10 users x 1 month-- <h1>$66.70</h1>+ <label for="due-today" class="inline-block label-title">Due today</label>+ <div id="due-today" class="not-editable-realm-field">+ $<span class="due-today-unit-price"></span> x+ {% if not manual_license_management %}+ {{ seat_count }}+ {% else %}+ <span class="due-today-license-count">{{ seat_count }}</span>+ {% endif %}+ users x+ <span class="due-today-duration"></span> month+ <h1>$<span class="due-today-price"></span></h1></div></div>diff --git a/web/src/billing/helpers.ts b/web/src/billing/helpers.tsindex c83a5f5e7da..d435635d066 100644--- a/web/src/billing/helpers.ts+++ b/web/src/billing/helpers.ts@@ -3,8 +3,6 @@ import {z} from "zod";import * as loading from "../loading";-import {page_params} from "./page_params";-export type FormDataObject = Record<string, string>;export const schedule_schema = z.enum(["monthly", "annual"]);@@ -106,10 +104,6 @@ export function format_money(cents: number): string {}).format(Number.parseFloat((cents / 100).toFixed(precision)));}-export function update_charged_amount(prices: Prices, schedule: keyof Prices): void {- $("#charged_amount").text(format_money(page_params.seat_count * prices[schedule]));-}-export function update_discount_details(organization_type: string): void {let discount_notice ="Your organization may be eligible for a discount on Zulip Cloud Standard. Organizations whose members are not employees are generally eligible.";diff --git a/web/src/billing/upgrade.ts b/web/src/billing/upgrade.tsindex 92b697db115..2712d76ffb3 100644--- a/web/src/billing/upgrade.ts+++ b/web/src/billing/upgrade.ts@@ -4,6 +4,9 @@ import * as helpers from "./helpers";import type {Prices} from "./helpers";import {page_params} from "./page_params";+let selected_schedule = "monthly";+let current_license_count = page_params.seat_count;+export const initialize = (): void => {$("#add-card-button").on("click", (e) => {const license_management = $<HTMLInputElement>(@@ -24,8 +27,24 @@ export const initialize = (): void => {monthly: page_params.monthly_price * (1 - page_params.percent_off / 100),};- $<HTMLInputElement>("input[type=radio][name=schedule]").on("change", function () {- helpers.update_charged_amount(prices, helpers.schedule_schema.parse(this.value));+ function update_due_today(schedule: string): void {+ let num_months = 12;+ if (schedule === "monthly") {+ num_months = 1;+ }+ $("#due-today .due-today-duration").text(num_months);+ const schedule_typed = helpers.schedule_schema.parse(schedule);+ $("#due-today .due-today-price").text(+ helpers.format_money(current_license_count * prices[schedule_typed]),+ );+ const unit_price = prices[schedule_typed] / num_months;+ $("#due-today .due-today-unit-price").text(helpers.format_money(unit_price));+ }++ update_due_today(selected_schedule);+ $<HTMLInputElement>("#payment-schedule-select").on("change", function () {+ selected_schedule = this.value;+ update_due_today(selected_schedule);});$("#autopay_annual_price_per_month").text(@@ -34,6 +53,20 @@ export const initialize = (): void => {$("#autopay_monthly_price").text(`Pay monthly ($${helpers.format_money(prices.monthly)}/user/month)`,);++ $<HTMLInputElement>("#manual_license_count").on("keyup", function () {+ $("#upgrade-licenses-change-error").text("");+ const license_count = Number.parseInt(this.value, 10);+ if (!license_count || license_count < page_params.seat_count) {+ $("#upgrade-licenses-change-error").text(+ `You must purchase licenses for all active users in your organization (minimum ${page_params.seat_count}).`,+ );+ return;+ }+ $("#due-today .due-today-license-count").text(license_count);+ current_license_count = license_count;+ update_due_today(selected_schedule);+ });};$(() => {diff --git a/web/styles/portico/billing.css b/web/styles/portico/billing.cssindex cfd48f81ad4..1c24d251019 100644--- a/web/styles/portico/billing.css+++ b/web/styles/portico/billing.css@@ -410,6 +410,7 @@ input[name="licenses"] {margin-bottom: 0;}+.upgrade-page-error,.sponsorship-field-error,.billing-page-error,.billing-page-success {