Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): surface 15% yearly savings in switch-to-yearly modal (#13095)

Abhimanyu Yadav02ff908a35b4
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
index 7116802a96..0cd62c1489 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
@@ -231,17 +231,122 @@ describe("YourPlanCard cycle toggle", () => {
fireEvent.click(yearly);
expect(
- await screen.findByText(/Switch billing to Yearly\?/i),
+ await screen.findByText(/Switch Pro to yearly billing\?/i),
+ ).toBeDefined();
+ expect(screen.getByText(/Save 15% with yearly billing\./i)).toBeDefined();
+ expect(
+ screen.getByText(
+ /Pro is \$42\.50\/month when billed yearly, charged as \$510\.00\/year instead of \$600\.00\/year monthly\./i,
+ ),
).toBeDefined();
expect(
screen.getByText(/charged the prorated difference immediately/i),
).toBeDefined();
- expect(screen.getByText(/\$510\.00/)).toBeDefined();
expect(
screen.getByRole("button", { name: /switch to yearly/i }),
).toBeDefined();
});
+ it("shows Max-specific yearly savings copy in the confirmation dialog", async () => {
+ server.use(
+ jsonHandler("get", "/api/credits/subscription", {
+ tier: "MAX",
+ monthly_cost: 32000,
+ billing_cycle: "monthly",
+ tier_costs: { PRO: 5000, MAX: 32000 },
+ tier_costs_yearly: { PRO: 51000, MAX: 326400 },
+ has_active_stripe_subscription: true,
+ status: "active",
+ }),
+ jsonHandler("get", "/api/credits/manage", {
+ url: "https://billing.stripe.com/p/test",
+ }),
+ );
+
+ render(<YourPlanCard />);
+
+ fireEvent.click(await screen.findByRole("radio", { name: /yearly/i }));
+
+ expect(
+ await screen.findByText(/Switch Max to yearly billing\?/i),
+ ).toBeDefined();
+ expect(
+ screen.getByText(
+ /Max is \$272\.00\/month when billed yearly, charged as \$3,264\.00\/year instead of \$3,840\.00\/year monthly\./i,
+ ),
+ ).toBeDefined();
+ expect(
+ screen.getByText(
+ /After this period, your plan renews yearly at \$3,264\.00\./i,
+ ),
+ ).toBeDefined();
+ });
+
+ it("opens the confirmation dialog with end-of-period copy when a yearly Pro user clicks Monthly", async () => {
+ server.use(
+ jsonHandler("get", "/api/credits/subscription", {
+ tier: "PRO",
+ monthly_cost: 51000,
+ billing_cycle: "yearly",
+ tier_costs: { PRO: 5000, MAX: 32000 },
+ tier_costs_yearly: { PRO: 51000, MAX: 326400 },
+ has_active_stripe_subscription: true,
+ status: "active",
+ }),
+ jsonHandler("get", "/api/credits/manage", {
+ url: "https://billing.stripe.com/p/test",
+ }),
+ );
+
+ render(<YourPlanCard />);
+
+ fireEvent.click(await screen.findByRole("radio", { name: /monthly/i }));
+
+ expect(
+ await screen.findByText(/Switch Pro to monthly billing\?/i),
+ ).toBeDefined();
+ expect(
+ screen.getByText(
+ /switch to monthly billing at the end of your current yearly period/i,
+ ),
+ ).toBeDefined();
+ expect(screen.getByText(/New monthly price: \$50\.00/)).toBeDefined();
+ });
+
+ it("falls back to the generic dialog title when prices are missing (NO_TIER-like)", async () => {
+ // BUSINESS tier exercises the generic-title fallback in getDialogTitle —
+ // the cycle toggle is still visible (BUSINESS isn't in the hidden set),
+ // but the title shouldn't read "Switch Team to yearly billing?" since
+ // BUSINESS is contact-sales and not a user-managed yearly tier.
+ server.use(
+ jsonHandler("get", "/api/credits/subscription", {
+ tier: "BUSINESS",
+ monthly_cost: 50000,
+ billing_cycle: "monthly",
+ has_active_stripe_subscription: true,
+ status: "active",
+ }),
+ jsonHandler("get", "/api/credits/manage", {
+ url: "https://billing.stripe.com/p/test",
+ }),
+ );
+
+ render(<YourPlanCard />);
+
+ fireEvent.click(await screen.findByRole("radio", { name: /yearly/i }));
+
+ expect(
+ await screen.findByText(/Switch billing to Yearly\?/i),
+ ).toBeDefined();
+ // No tier_costs / tier_costs_yearly in the payload — body falls back to
+ // proration-only copy without the savings/pricing lines.
+ expect(
+ screen.getByText(
+ /charged the prorated difference immediately\. After this period, your plan renews on the new yearly cadence\./i,
+ ),
+ ).toBeDefined();
+ });
+
it("fires updateTier with billing_cycle on confirm", async () => {
let capturedBody: { tier?: string; billing_cycle?: string } | null = null;
server.use(
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx
index 4c9d260ff9..fe2c4b3f4c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx
@@ -8,6 +8,7 @@ interface Props {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
targetCycle: "monthly" | "yearly";
+ title?: string;
body: string;
isSaving: boolean;
onConfirm: () => void;
@@ -17,6 +18,7 @@ export function SwitchCycleDialog({
isOpen,
onOpenChange,
targetCycle,
+ title,
body,
isSaving,
onConfirm,
@@ -25,7 +27,7 @@ export function SwitchCycleDialog({
return (
<Dialog
- title={`Switch billing to ${targetLabel}?`}
+ title={title ?? `Switch billing to ${targetLabel}?`}
styling={{ maxWidth: "440px" }}
controlled={{ isOpen, set: onOpenChange }}
>
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/YourPlanCard.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/YourPlanCard.tsx
index e9093c556a..14a959d7f1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/YourPlanCard.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/YourPlanCard.tsx
@@ -39,6 +39,7 @@ export function YourPlanCard({ index = 0 }: Props) {
pendingTierDowngrade,
pendingTierDowngradeLabel,
isCycleToggleVisible,
+ cycleDialogTitle,
cycleDialogBody,
tierUpgradeDialogBody,
tierDowngradeDialogBody,
@@ -205,6 +206,7 @@ export function YourPlanCard({ index = 0 }: Props) {
if (!open) onCancelCycleSwitch();
}}
targetCycle={pendingCycle}
+ title={cycleDialogTitle || undefined}
body={cycleDialogBody}
isSaving={isUpdatingTier}
onConfirm={onConfirmCycleSwitch}
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts
index e3be4d7876..c0e66514ab 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts
@@ -328,17 +328,62 @@ export function useYourPlanCard() {
setPendingCycle(null);
}
+ function getDialogTitle(): string {
+ if (!pendingCycle) return "";
+ const tierLabel = effectiveTier ? PLAN_LABEL[effectiveTier] : null;
+ // NO_TIER / unknown tiers don't have a meaningful label for the title
+ // ("Switch No active subscription to yearly billing?" reads as nonsense).
+ if (
+ !tierLabel ||
+ effectiveTier === "NO_TIER" ||
+ effectiveTier === "BUSINESS"
+ ) {
+ return pendingCycle === "yearly"
+ ? "Switch billing to Yearly?"
+ : "Switch billing to Monthly?";
+ }
+ return pendingCycle === "yearly"
+ ? `Switch ${tierLabel} to yearly billing?`
+ : `Switch ${tierLabel} to monthly billing?`;
+ }
+
function getDialogBody(): string {
if (!pendingCycle) return "";
if (pendingCycle === "yearly") {
const yearly =
currentYearlyCents !== undefined ? formatCents(currentYearlyCents) : "";
- return [
+ const tierLabel = effectiveTier ? PLAN_LABEL[effectiveTier] : null;
+ const prorationLine = [
"You'll be charged the prorated difference immediately.",
yearly
? `After this period, your plan renews yearly at ${yearly}.`
: "After this period, your plan renews on the new yearly cadence.",
].join(" ");
+ // Surface the yearly savings up front when we have both prices — the
+ // 15% discount is the user's primary motivator for accepting the
+ // prorated charge and shouldn't be buried.
+ if (
+ currentMonthlyCents !== undefined &&
+ currentYearlyCents !== undefined &&
+ currentMonthlyCents > 0 &&
+ currentYearlyCents < currentMonthlyCents * 12
+ ) {
+ const annualMonthlyCents = currentMonthlyCents * 12;
+ const savingsPercent = Math.round(
+ ((annualMonthlyCents - currentYearlyCents) / annualMonthlyCents) *
+ 100,
+ );
+ const monthlyEquivalent = formatCents(
+ Math.round(currentYearlyCents / 12),
+ );
+ const annualMonthly = formatCents(annualMonthlyCents);
+ const savingsLine = `Save ${savingsPercent}% with yearly billing.`;
+ const pricingLine = tierLabel
+ ? `${tierLabel} is ${monthlyEquivalent}/month when billed yearly, charged as ${yearly}/year instead of ${annualMonthly}/year monthly.`
+ : `It's ${monthlyEquivalent}/month when billed yearly, charged as ${yearly}/year instead of ${annualMonthly}/year monthly.`;
+ return [savingsLine, pricingLine, prorationLine].join(" ");
+ }
+ return prorationLine;
}
const monthly =
currentMonthlyCents !== undefined ? formatCents(currentMonthlyCents) : "";
@@ -451,6 +496,7 @@ export function useYourPlanCard() {
? (PLAN_LABEL[pendingTierDowngrade] ?? pendingTierDowngrade)
: null,
isCycleToggleVisible,
+ cycleDialogTitle: getDialogTitle(),
cycleDialogBody: getDialogBody(),
tierUpgradeDialogBody: getTierUpgradeDialogBody(),
tierDowngradeDialogBody: getTierDowngradeDialogBody(),