#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Add a plan comparison to Usage and Billing (#8142)
ConnorYohdb2e901bc78f
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex 3a940819ce..373c1ad94d 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -7579,6 +7579,49 @@ plan = "Plan"procurement = "Procurement"usage = "Usage"+[portal.billing.compare]+current = "Current"+enterpriseData = "Data residency and SCIM"+enterpriseName = "Enterprise"+enterprisePrice = "Under your agreement"+enterpriseProcessing = "Metered or flat"+enterpriseSignIn = "SAML and auditing"+enterpriseSupport = "Uptime SLAs, deployment help"+enterpriseUsers = "No ceiling"+enterpriseWhere = "Plus multi-node and air-gapped"+exploreEnterprise = "Explore Enterprise"+freeData = "Stays where you run it"+freeName = "Free"+freePrice = "No card, no expiry"+freeProcessing = "{{allowance}} credits a month"+freeProcessingUnknown = "A monthly credit allowance"+freeSignIn = "Email, Google and SSO"+freeSignInNote = "OAuth2/OIDC"+freeSupport = "Community"+freeUsers = "Up to {{users}}"+freeUsersUnknown = "A small team"+freeWhere = "Cloud, desktop or self-hosted"+lede = "Every plan includes every PDF tool and SSO. What changes is how many people use it, where it runs, and what support you get."+open = "Compare plans"+rowData = "Your data"+rowHeader = "Feature"+rowProcessing = "Processing"+rowSignIn = "Sign-in"+rowSupport = "Support"+rowUsers = "Users"+rowWhere = "Where it runs"+teamData = "Google Drive, your own database"+teamName = "Team"+teamPrice = "$99/mo per 100 users"+teamProcessing = "{{allowance}} a month, then metered"+teamProcessingUnknown = "A larger allowance, then metered"+teamSignIn = "The same"+teamSupport = "Email"+teamUsers = "100 per block"+teamWhere = "Cloud, desktop or self-hosted"+title = "Compare plans"+upgradeTeam = "Upgrade to Team"+[portal.billing.cycle]credits = "Credits"creditsNote = "{{units}} used · includes free and prepaid credits"diff --git a/frontend/editor/src/proprietary/billing/BillingScreen.tsx b/frontend/editor/src/proprietary/billing/BillingScreen.tsxindex 528fb423ab..cc7415ade1 100644--- a/frontend/editor/src/proprietary/billing/BillingScreen.tsx+++ b/frontend/editor/src/proprietary/billing/BillingScreen.tsx@@ -1,7 +1,11 @@import type { ReactNode } from "react";-import { useCallback, useMemo } from "react";+import { useCallback, useMemo, useState } from "react";import { useTranslation } from "react-i18next";import { Skeleton } from "@app/ui";+import {+ ComparePlansModal,+ type ComparePlan,+} from "@app/billing/ComparePlansModal";import { formatMinor } from "@app/billing/format";import { KvRow } from "@app/billing/KvRow";import { TeamPlanRow } from "@app/billing/TeamPlanRow";@@ -127,6 +131,7 @@ export function BillingScreen({extras,}: BillingScreenProps) {const { t } = useTranslation();+ const [comparing, setComparing] = useState(false);const jump = useCallback((id: string) => {document@@ -271,6 +276,36 @@ export function BillingScreen({t,]);+ /**+ * The column the matrix marks as the caller's own. A Server licence sits in the Team column:+ * it is the same hundred-user deal the cloud sells, bought locally instead.+ */+ const currentPlan: ComparePlan | null = serverPlan+ ? serverPlan.licenseType === "ENTERPRISE"+ ? "enterprise"+ : "team"+ : !wallet+ ? null+ : paying || teamHeld+ ? "team"+ : "free";++ /**+ * {@code freeAllowance} is whatever grant the WALLET carries, so it describes the Team column+ * only where the wallet itself is paying. A local Server licence puts the caller in the Team+ * column while its wallet is still free, and quoting that free grant as Team's included+ * allowance would overstate what the plan buys. The user ceiling is not overloaded this way —+ * it stays the free one whatever is held — so it always describes the Free column.+ */+ const walletPays = Boolean(wallet) && (teamHeld || paying);+ const compareTeamAllowance = walletPays+ ? (wallet?.freeAllowance ?? null)+ : null;+ const compareFreeAllowance = walletPays+ ? null+ : (wallet?.freeAllowance ?? null);+ const compareFreeUsers = wallet?.freeUserAllowance ?? null;+const creditUnits = (wallet?.spendUnitsThisPeriod ?? 0) + pendingUnits;const occupiedSeats = serverPlan? serverPlan.usersInUse@@ -354,9 +389,20 @@ export function BillingScreen({{(identity || legacyPlan) && (<><section id="ub-plan" className="billing-sec">- <span className="billing-eyebrow">- {t("portal.billing.section.plan", "Your plan")}- </span>+ <div className="billing-eyebrow-row">+ <span className="billing-eyebrow">+ {t("portal.billing.section.plan", "Your plan")}+ </span>+ {identity && (+ <button+ type="button"+ className="billing-compare-open"+ onClick={() => setComparing(true)}+ >+ {t("portal.billing.compare.open", "Compare plans")}+ </button>+ )}+ </div>{legacyPlan}{identity && (<div className="billing-id">@@ -588,6 +634,31 @@ export function BillingScreen({</div>)}+ <ComparePlansModal+ open={comparing}+ onClose={() => setComparing(false)}+ currentPlan={currentPlan}+ freeUserLimit={compareFreeUsers}+ freeAllowance={compareFreeAllowance}+ teamAllowance={compareTeamAllowance}+ onUpgradeTeam={+ onAddCapacity && currentPlan === "free"+ ? () => {+ setComparing(false);+ onAddCapacity();+ }+ : undefined+ }+ onExploreEnterprise={+ onEnterpriseQuote && currentPlan !== "enterprise"+ ? () => {+ setComparing(false);+ onEnterpriseQuote();+ }+ : undefined+ }+ />+{extras}</div></div>diff --git a/frontend/editor/src/proprietary/billing/ComparePlansModal.test.tsx b/frontend/editor/src/proprietary/billing/ComparePlansModal.test.tsxnew file mode 100644index 0000000000..0601a5b16c--- /dev/null+++ b/frontend/editor/src/proprietary/billing/ComparePlansModal.test.tsx@@ -0,0 +1,165 @@+import { expect, it, vi } from "vitest";+import { fireEvent, render as rtlRender, screen } from "@testing-library/react";+import { MantineProvider } from "@mantine/core";+import type { ReactNode } from "react";++vi.mock("react-i18next", () => ({+ useTranslation: () => ({+ t: (_key: string, def?: string, vars?: Record<string, unknown>) =>+ def && vars+ ? def.replace(/\{\{(\w+)\}\}/g, (_m, k) => String(vars[k] ?? ""))+ : (def ?? _key),+ i18n: { changeLanguage: vi.fn() },+ }),+}));++import { BillingScreen } from "@app/billing/BillingScreen";+import { ComparePlansModal } from "@app/billing/ComparePlansModal";+import { freeWallet } from "@app/billing/walletFixtures";++/** Both @app/ui controls the matrix uses are Mantine-backed, so they need its provider. */+const render = (ui: ReactNode) =>+ rtlRender(<MantineProvider>{ui}</MantineProvider>);++function open(props: Partial<Parameters<typeof ComparePlansModal>[0]> = {}) {+ return render(+ <ComparePlansModal+ open+ onClose={() => {}}+ currentPlan="free"+ freeUserLimit={5}+ freeAllowance={500}+ {...props}+ />,+ );+}++it("quotes the figures it was given rather than a fixed number", () => {+ open({ freeUserLimit: 12, freeAllowance: 1000 });+ expect(screen.getByText("Up to 12")).toBeInTheDocument();+ expect(screen.getByText("1,000 credits a month")).toBeInTheDocument();+});++it.each([null, 0])(+ "describes the allowance in words when the host reports %s",+ (allowance) => {+ open({ freeUserLimit: null, freeAllowance: allowance as number | null });+ expect(screen.getByText("A monthly credit allowance")).toBeInTheDocument();+ expect(screen.getByText("A small team")).toBeInTheDocument();+ },+);++it("states the shape of Team's allowance when no figure is available", () => {+ open();+ expect(+ screen.getByText("A larger allowance, then metered"),+ ).toBeInTheDocument();+});++it("marks only the caller's own plan", () => {+ open({ currentPlan: "team" });+ const marks = screen.getAllByText("Current");+ expect(marks).toHaveLength(1);+ expect(marks[0].closest("th")).toHaveTextContent("Team");+});++/** SSO is on every plan, so the row must not imply Team adds anything to sign-in. */+it("does not sell Team on sign-in", () => {+ open();+ expect(screen.getByText("Email, Google and SSO")).toBeInTheDocument();+ expect(screen.getByText("The same")).toBeInTheDocument();+ expect(screen.getByText("SAML and auditing")).toBeInTheDocument();+});++it("drops a door the host did not open", () => {+ open({ onUpgradeTeam: undefined, onExploreEnterprise: undefined });+ expect(screen.queryByText("Upgrade to Team")).not.toBeInTheDocument();+ expect(screen.queryByText("Explore Enterprise")).not.toBeInTheDocument();+});++/**+ * The close and the hand-off land in one commit, so the matrix never sits over the flow it+ * started. They are not ordered within the handler, and nothing should depend on that.+ */+it("leaves the matrix closed once the procurement flow is away", () => {+ const onExploreEnterprise = vi.fn();+ render(+ <BillingScreen+ wallet={freeWallet}+ onEnterpriseQuote={onExploreEnterprise}+ />,+ );+ fireEvent.click(screen.getByRole("button", { name: "Compare plans" }));+ expect(screen.getByText("Where it runs")).toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: "Explore Enterprise" }));+ expect(onExploreEnterprise).toHaveBeenCalledOnce();+ expect(screen.queryByText("Where it runs")).not.toBeInTheDocument();+});++/**+ * A local Server licence sits in the Team column while its wallet is still free, so the grant the+ * wallet reports is the free one and must not be quoted as what Team includes.+ */+it("does not quote a free grant as a Server licence's Team allowance", () => {+ render(+ <BillingScreen+ wallet={{ ...freeWallet, freeAllowance: 1000 }}+ serverPlan={{ licenseType: "SERVER", maxUsers: 100, usersInUse: 12 }}+ />,+ );+ fireEvent.click(screen.getByRole("button", { name: "Compare plans" }));+ expect(+ screen.queryByText("1,000 a month, then metered"),+ ).not.toBeInTheDocument();+ expect(+ screen.getByText("A larger allowance, then metered"),+ ).toBeInTheDocument();+ expect(screen.getByText("1,000 credits a month")).toBeInTheDocument();+});++/** An Enterprise licence needs neither door, and the enterprise banner already gates itself. */+it("sells nothing to an enterprise licence", () => {+ render(+ <BillingScreen+ wallet={freeWallet}+ serverPlan={{ licenseType: "ENTERPRISE", maxUsers: 0, usersInUse: 12 }}+ onAddCapacity={() => {}}+ onEnterpriseQuote={() => {}}+ />,+ );+ fireEvent.click(screen.getByRole("button", { name: "Compare plans" }));+ expect(screen.getByText("Where it runs")).toBeInTheDocument();+ expect(screen.queryByText("Upgrade to Team")).not.toBeInTheDocument();+ expect(screen.queryByText("Explore Enterprise")).not.toBeInTheDocument();+});++it("keeps the free user ceiling in the Free column for a team that holds Team", () => {+ render(+ <BillingScreen+ wallet={{+ ...freeWallet,+ freeUserAllowance: 5,+ team: { held: true, licensedUsers: 100, usersInUse: 6 },+ }}+ />,+ );+ fireEvent.click(screen.getByRole("button", { name: "Compare plans" }));+ expect(screen.getByText("Up to 5")).toBeInTheDocument();+ expect(screen.queryByText("A small team")).not.toBeInTheDocument();+});++it("offers no upgrade to a team that already holds one", () => {+ render(+ <BillingScreen+ wallet={{+ ...freeWallet,+ team: { held: true, licensedUsers: 100, usersInUse: 6 },+ }}+ onAddCapacity={() => {}}+ onEnterpriseQuote={() => {}}+ />,+ );+ fireEvent.click(screen.getByRole("button", { name: "Compare plans" }));+ expect(screen.queryByText("Upgrade to Team")).not.toBeInTheDocument();+ expect(screen.getByText("Explore Enterprise")).toBeInTheDocument();+});diff --git a/frontend/editor/src/proprietary/billing/ComparePlansModal.tsx b/frontend/editor/src/proprietary/billing/ComparePlansModal.tsxnew file mode 100644index 0000000000..92235debc9--- /dev/null+++ b/frontend/editor/src/proprietary/billing/ComparePlansModal.tsx@@ -0,0 +1,264 @@+import { useMemo } from "react";+import { useTranslation } from "react-i18next";+import { Button, Modal } from "@app/ui";++export type ComparePlan = "free" | "team" | "enterprise";++export interface ComparePlansModalProps {+ open: boolean;+ onClose: () => void;+ /** Marks a column as the caller's own plan; null leaves every column unmarked. */+ currentPlan: ComparePlan | null;+ /** Null where the host cannot read one, which drops the figure rather than guessing at it. */+ freeUserLimit: number | null;+ freeAllowance: number | null;+ /**+ * A free wallet carries no Team allowance, so the figure is only ever available to a host that+ * already holds Team. Absent, the row states the shape of the deal without inventing a number.+ */+ teamAllowance?: number | null;+ /** Leader-only doors. An omitted callback drops its button rather than rendering a dead one. */+ onUpgradeTeam?: () => void;+ onExploreEnterprise?: () => void;+}++/** A zero from a host that could not read the real figure is an absence, not a ceiling of none. */+function quoted(n: number | null | undefined): string | null {+ return n != null && n > 0 ? n.toLocaleString() : null;+}++interface Column {+ plan: ComparePlan;+ name: string;+ price: string;+}++interface Row {+ key: string;+ label: string;+ free: string;+ /** Qualifies the Free cell without repeating it in every column. */+ freeNote?: string;+ team: string;+ enterprise: string;+}++/**+ * The plan matrix, opened from the plan section of Usage and Billing.+ *+ * <p>Every row states something the plans genuinely differ on. Sign-in is the exception and is+ * kept deliberately: SSO is on all three, and saying so is the point of the row rather than a gap+ * in it. Nothing here claims Team centralises identity across a fleet, because it does not: each+ * instance configures its own provider, and the fleet the wallet knows about is a seat total.+ */+export function ComparePlansModal({+ open,+ onClose,+ currentPlan,+ freeUserLimit,+ freeAllowance,+ teamAllowance,+ onUpgradeTeam,+ onExploreEnterprise,+}: ComparePlansModalProps) {+ const { t } = useTranslation();++ const columns = useMemo<Column[]>(+ () => [+ {+ plan: "free",+ name: t("portal.billing.compare.freeName", "Free"),+ price: t("portal.billing.compare.freePrice", "No card, no expiry"),+ },+ {+ plan: "team",+ name: t("portal.billing.compare.teamName", "Team"),+ price: t("portal.billing.compare.teamPrice", "$99/mo per 100 users"),+ },+ {+ plan: "enterprise",+ name: t("portal.billing.compare.enterpriseName", "Enterprise"),+ price: t(+ "portal.billing.compare.enterprisePrice",+ "Under your agreement",+ ),+ },+ ],+ [t],+ );++ const rows = useMemo<Row[]>(() => {+ const users = quoted(freeUserLimit);+ const freeCredits = quoted(freeAllowance);+ const teamCredits = quoted(teamAllowance);++ return [+ {+ key: "users",+ label: t("portal.billing.compare.rowUsers", "Users"),+ free:+ users != null+ ? t("portal.billing.compare.freeUsers", "Up to {{users}}", {+ users,+ })+ : t("portal.billing.compare.freeUsersUnknown", "A small team"),+ team: t("portal.billing.compare.teamUsers", "100 per block"),+ enterprise: t("portal.billing.compare.enterpriseUsers", "No ceiling"),+ },+ {+ key: "signin",+ label: t("portal.billing.compare.rowSignIn", "Sign-in"),+ free: t("portal.billing.compare.freeSignIn", "Email, Google and SSO"),+ freeNote: t("portal.billing.compare.freeSignInNote", "OAuth2/OIDC"),+ team: t("portal.billing.compare.teamSignIn", "The same"),+ enterprise: t(+ "portal.billing.compare.enterpriseSignIn",+ "SAML and auditing",+ ),+ },+ {+ key: "where",+ label: t("portal.billing.compare.rowWhere", "Where it runs"),+ free: t(+ "portal.billing.compare.freeWhere",+ "Cloud, desktop or self-hosted",+ ),+ team: t(+ "portal.billing.compare.teamWhere",+ "Cloud, desktop or self-hosted",+ ),+ enterprise: t(+ "portal.billing.compare.enterpriseWhere",+ "Plus multi-node and air-gapped",+ ),+ },+ {+ key: "processing",+ label: t("portal.billing.compare.rowProcessing", "Processing"),+ free:+ freeCredits != null+ ? t(+ "portal.billing.compare.freeProcessing",+ "{{allowance}} credits a month",+ { allowance: freeCredits },+ )+ : t(+ "portal.billing.compare.freeProcessingUnknown",+ "A monthly credit allowance",+ ),+ team:+ teamCredits != null+ ? t(+ "portal.billing.compare.teamProcessing",+ "{{allowance}} a month, then metered",+ { allowance: teamCredits },+ )+ : t(+ "portal.billing.compare.teamProcessingUnknown",+ "A larger allowance, then metered",+ ),+ enterprise: t(+ "portal.billing.compare.enterpriseProcessing",+ "Metered or flat",+ ),+ },+ {+ key: "data",+ label: t("portal.billing.compare.rowData", "Your data"),+ free: t("portal.billing.compare.freeData", "Stays where you run it"),+ team: t(+ "portal.billing.compare.teamData",+ "Google Drive, your own database",+ ),+ enterprise: t(+ "portal.billing.compare.enterpriseData",+ "Data residency and SCIM",+ ),+ },+ {+ key: "support",+ label: t("portal.billing.compare.rowSupport", "Support"),+ free: t("portal.billing.compare.freeSupport", "Community"),+ team: t("portal.billing.compare.teamSupport", "Email"),+ enterprise: t(+ "portal.billing.compare.enterpriseSupport",+ "Uptime SLAs, deployment help",+ ),+ },+ ];+ }, [t, freeUserLimit, freeAllowance, teamAllowance]);++ return (+ <Modal+ open={open}+ onClose={onClose}+ width="xl"+ title={t("portal.billing.compare.title", "Compare plans")}+ subtitle={t(+ "portal.billing.compare.lede",+ "Every plan includes every PDF tool and SSO. What changes is how many people use it, where it runs, and what support you get.",+ )}+ footer={+ onUpgradeTeam || onExploreEnterprise ? (+ <div className="billing-compare__actions">+ {onUpgradeTeam && (+ <Button onClick={onUpgradeTeam}>+ {t("portal.billing.compare.upgradeTeam", "Upgrade to Team")}+ </Button>+ )}+ {onExploreEnterprise && (+ <Button variant="secondary" onClick={onExploreEnterprise}>+ {t(+ "portal.billing.compare.exploreEnterprise",+ "Explore Enterprise",+ )}+ </Button>+ )}+ </div>+ ) : undefined+ }+ >+ <table className="billing-compare">+ <thead>+ <tr>+ <th scope="col">+ <span className="sr-only">+ {t("portal.billing.compare.rowHeader", "Feature")}+ </span>+ </th>+ {columns.map((c) => (+ <th key={c.plan} scope="col" className="billing-compare__head">+ <span className="billing-compare__plan">+ {c.name}+ {currentPlan === c.plan && (+ <span className="billing-compare__current">+ {t("portal.billing.compare.current", "Current")}+ </span>+ )}+ </span>+ <span className="billing-compare__price">{c.price}</span>+ </th>+ ))}+ </tr>+ </thead>+ <tbody>+ {rows.map((r) => (+ <tr key={r.key}>+ <th scope="row" className="billing-compare__label">+ {r.label}+ </th>+ <td className="billing-compare__cell">+ {r.free}+ {r.freeNote && (+ <span className="billing-compare__note">{r.freeNote}</span>+ )}+ </td>+ <td className="billing-compare__cell">{r.team}</td>+ <td className="billing-compare__cell">{r.enterprise}</td>+ </tr>+ ))}+ </tbody>+ </table>+ </Modal>+ );+}diff --git a/frontend/editor/src/proprietary/billing/billing-screen.css b/frontend/editor/src/proprietary/billing/billing-screen.cssindex 4734dbb0e6..a42c328c63 100644--- a/frontend/editor/src/proprietary/billing/billing-screen.css+++ b/frontend/editor/src/proprietary/billing/billing-screen.css@@ -511,3 +511,134 @@.billing-id__action {margin-left: auto;}++/* The plan matrix. Column widths are equal and fixed so a long cell wraps instead of+ stealing width from its neighbours, which is what keeps the three plans comparable. */+.billing-compare {+ width: 100%;+ border-collapse: collapse;+ table-layout: fixed;+}++.billing-compare__head {+ width: 26%;+ padding: 0 0 0.75rem 1.125rem;+ text-align: start;+ vertical-align: bottom;+}++.billing-compare__plan {+ display: flex;+ flex-wrap: wrap;+ gap: 0.4375rem;+ align-items: center;+ font-size: 0.9375rem;+ font-weight: 600;+ color: var(--c-text);+}++.billing-compare__current {+ padding: 0.0625rem 0.4375rem;+ font-size: 0.625rem;+ font-weight: 700;+ letter-spacing: 0.04em;+ text-transform: uppercase;+ color: var(--c-accent-text);+ border: 1px solid var(--c-primary-subtle);+ border-radius: 1.25rem;+}++.billing-compare__price {+ display: block;+ margin-top: 0.1875rem;+ font-size: 0.75rem;+ font-weight: 400;+ color: var(--c-text-subtle);+}++.billing-compare__label {+ width: 22%;+ padding: 0.8125rem 0.75rem 0.8125rem 0;+ font-size: 0.75rem;+ font-weight: 400;+ text-align: start;+ vertical-align: top;+ color: var(--c-text-subtle);+}++.billing-compare__cell {+ padding: 0.8125rem 0.75rem 0.8125rem 1.125rem;+ font-size: 0.8125rem;+ line-height: 1.45;+ vertical-align: top;+ color: var(--c-text);+}++.billing-compare thead th {+ border-bottom: 1px solid var(--c-border);+}++.billing-compare tbody tr + tr th,+.billing-compare tbody tr + tr td {+ border-top: 1px solid var(--c-border-subtle);+}++.billing-compare__note {+ display: block;+ margin-top: 0.125rem;+ font-size: 0.71875rem;+ color: var(--c-text-subtle);+}++.billing-compare__actions {+ display: flex;+ flex-wrap: wrap;+ gap: 0.625rem;+}++/* Sits on the eyebrow row, so it reads as a quiet aside to the plan rather than a fourth CTA. */+.billing-compare-open {+ padding: 0;+ font: inherit;+ font-size: 0.75rem;+ font-weight: 600;+ color: var(--c-accent-text);+ cursor: pointer;+ background: none;+ border: none;+}++.billing-compare-open:hover {+ text-decoration: underline;+}++@media (max-width: 40rem) {+ /* Three plans cannot stay side by side on a phone; the label column goes and each+ cell carries its own heading instead. */+ .billing-compare,+ .billing-compare tbody,+ .billing-compare tbody tr,+ .billing-compare__cell {+ display: block;+ }++ .billing-compare thead {+ display: none;+ }++ .billing-compare__label {+ display: block;+ width: auto;+ padding: 0.875rem 0 0.25rem;+ font-weight: 600;+ color: var(--c-text);+ }++ .billing-compare__cell {+ padding: 0.25rem 0 0.25rem 0.875rem;+ }++ .billing-compare tbody tr + tr td {+ border-top: none;+ }+}