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): smooth Monthly↔Yearly price transition on PlanCard (#13100)
Abhimanyu Yadavcee87967e7ee
diff --git a/autogpt_platform/frontend/package.json b/autogpt_platform/frontend/package.jsonindex ca398fcefa..c13b33a7fc 100644--- a/autogpt_platform/frontend/package.json+++ b/autogpt_platform/frontend/package.json@@ -37,6 +37,7 @@"@ferrucc-io/emoji-picker": "0.0.48","@hookform/resolvers": "5.2.2","@next/third-parties": "15.4.6",+ "@number-flow/react": "0.6.0","@phosphor-icons/react": "2.1.10","@posthog/react": "1.7.0","@radix-ui/react-accordion": "1.2.12",diff --git a/autogpt_platform/frontend/pnpm-lock.yaml b/autogpt_platform/frontend/pnpm-lock.yamlindex 23856ce107..c5f7c2b67e 100644--- a/autogpt_platform/frontend/pnpm-lock.yaml+++ b/autogpt_platform/frontend/pnpm-lock.yaml@@ -27,6 +27,9 @@ importers:'@next/third-parties':specifier: 15.4.6version: 15.4.6([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])+ '@number-flow/react':+ specifier: 0.6.0'@phosphor-icons/react':specifier: 2.1.10@@ -1926,6 +1929,12 @@ packages:resolution: {integrity: sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA==}engines: {node: '>=12.4.0'}+ '@number-flow/[email protected]':+ resolution: {integrity: sha512-77Yfc9+zkV2UDSP8phhZzxJGuwxi/Tt1TikmipL+1r3e9GFKEYDZ1XwInj67NoSt3OnOB0KLvvcl3lfPZgBHVQ==}+ peerDependencies:+ react: ^18 || ^19+ react-dom: ^18 || ^19+'@open-draft/[email protected]':resolution: {integrity: sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==}@@ -5379,6 +5388,9 @@ packages:deprecated: This version is no longer supported. Please see https://eslint.org/version-support for other options.hasBin: true+ resolution: {integrity: sha512-Epxrv+Nr/CaL4ZcFGPJIYLWFom+YeV1DqMLHJoEd9SYRxNbaFruBwfEX/kkHUJf55j2+TUbmDcmuilbP1TmXHA==}+resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==}engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}@@ -6929,6 +6941,9 @@ packages:resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==}+ resolution: {integrity: sha512-K8flNq2Wqus53vjp/btVo3qXFkagF8dIdYavreBfE7hlvFFG/b1HMGEH6nZL+mlrJ+4lbLP9OmPv3t2rmRkpSQ==}+resolution: {integrity: sha512-wOPJoz5om7jMJQick9zU1S/Q+joL+B2DZTZxfCleHEcUzjUnPoujGod4+nAmUWb+G9TwZnyv+mfNqlyfEi8Zag==}peerDependencies:@@ -10488,6 +10503,13 @@ snapshots:'@nolyfill/[email protected]': {}+ dependencies:+ esm-env: 1.2.2+ number-flow: 0.6.0+ react: 18.3.1+ react-dom: 18.3.1([email protected])+'@open-draft/[email protected]': {}'@open-draft/[email protected]':@@ -14650,6 +14672,8 @@ snapshots:transitivePeerDependencies:- supports-color+ [email protected]: {}+dependencies:acorn: 8.15.0@@ -16597,6 +16621,10 @@ snapshots:dependencies:boolbase: 1.0.0+ dependencies:+ esm-env: 1.2.2+[email protected]([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected]):dependencies:'@standard-schema/spec': 1.0.0diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/SubscriptionStep.test.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/SubscriptionStep.test.tsxindex d41c7c575f..d21b7aa835 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/SubscriptionStep.test.tsx+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/__tests__/SubscriptionStep.test.tsx@@ -43,10 +43,10 @@ describe("SubscriptionStep", () => {test("defaults to yearly billing with the monthly-equivalent price and the annual charge", () => {render(<SubscriptionStep />);expect(useOnboardingWizardStore.getState().selectedBilling).toBe("yearly");- expect(screen.getByText("$42.50")).toBeDefined();- expect(screen.getByText("$272.00")).toBeDefined();- expect(screen.getByText("Charged today: $510.00")).toBeDefined();- expect(screen.getByText("Charged today: $3,264.00")).toBeDefined();+ expect(screen.getByLabelText("$42.50")).toBeDefined();+ expect(screen.getByLabelText("$272.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $510.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $3,264.00")).toBeDefined();expect(screen.getAllByText(/Save 15%/).length).toBeGreaterThan(0);});@@ -54,10 +54,10 @@ describe("SubscriptionStep", () => {render(<SubscriptionStep />);fireEvent.click(screen.getByRole("button", { name: /Monthly billing/i }));expect(useOnboardingWizardStore.getState().selectedBilling).toBe("monthly");- expect(screen.getByText("$50.00")).toBeDefined();- expect(screen.getByText("$320.00")).toBeDefined();- expect(screen.getByText("Charged today: $50.00")).toBeDefined();- expect(screen.getByText("Charged today: $320.00")).toBeDefined();+ expect(screen.getByLabelText("$50.00")).toBeDefined();+ expect(screen.getByLabelText("$320.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $50.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $320.00")).toBeDefined();});test("selecting Pro persists selectedPlan, submits the profile, and redirects to Stripe Checkout", async () => {diff --git a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsx b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsxindex 11f18bcc12..33c6499fbe 100644--- a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsx@@ -145,10 +145,10 @@ describe("PaywallModal — Monthly/Yearly cycle toggle", () => {// PRO yearly = 51000 cents → $42.50/mo primary, $510.00 charged today.// MAX yearly = 326400 cents → $272.00/mo primary, $3,264.00 charged today.- expect(screen.getByText("$42.50")).toBeDefined();- expect(screen.getByText("$272.00")).toBeDefined();- expect(screen.getByText("Charged today: $510.00")).toBeDefined();- expect(screen.getByText("Charged today: $3,264.00")).toBeDefined();+ expect(screen.getByLabelText("$42.50")).toBeDefined();+ expect(screen.getByLabelText("$272.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $510.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $3,264.00")).toBeDefined();});it("toggling Monthly switches displayed prices to the full monthly amounts", async () => {@@ -166,10 +166,10 @@ describe("PaywallModal — Monthly/Yearly cycle toggle", () => {// PRO monthly = 5000 cents = $50.00 (primary), $50.00 charged todayawait waitFor(() => {- expect(screen.getByText("$50.00")).toBeDefined();- expect(screen.getByText("$320.00")).toBeDefined();- expect(screen.getByText("Charged today: $50.00")).toBeDefined();- expect(screen.getByText("Charged today: $320.00")).toBeDefined();+ expect(screen.getByLabelText("$50.00")).toBeDefined();+ expect(screen.getByLabelText("$320.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $50.00")).toBeDefined();+ expect(screen.getByLabelText("Charged today: $320.00")).toBeDefined();});});});diff --git a/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsx b/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsxindex 82fe7cbd6b..a80e6738dd 100644--- a/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsx+++ b/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsx@@ -1,15 +1,18 @@"use client";+import NumberFlow from "@number-flow/react";import { motion, useReducedMotion } from "framer-motion";import { Button } from "@/components/atoms/Button/Button";import { Text } from "@/components/atoms/Text/Text";import { cn } from "@/lib/utils";import { CheckIcon, StarIcon } from "@phosphor-icons/react";-import { type Country, formatPrice } from "./countries";+import { type Country } from "./countries";import { PLAN_KEYS, type PlanDef, type PlanKey } from "./plans";import { computePlanPricing } from "./computePricing";+const ZERO_DECIMAL_CODES = new Set(["JPY", "KRW", "HUF", "CLP"]);+interface Props {plan: PlanDef;country: Country;@@ -29,15 +32,23 @@ export function PlanCard({loading = false,disabled = false,}: Props) {- const { primaryPrice, monthlyOriginal, chargedToday, discountPercent } =- computePlanPricing({- plan,- country,- isYearly,- });+ const { primaryPrice, chargedToday } = computePlanPricing({+ plan,+ country,+ isYearly,+ });const hl = plan.highlighted;const isTeam = plan.key === PLAN_KEYS.TEAM;const reduceMotion = useReducedMotion();+ const decimalDigits = ZERO_DECIMAL_CODES.has(country.currencyCode) ? 0 : 2;+ const moneyFormat = {+ style: "currency",+ currency: country.currencyCode,+ currencyDisplay: "symbol",+ minimumFractionDigits: decimalDigits,+ maximumFractionDigits: decimalDigits,+ } as const;+ const moneyFormatter = new Intl.NumberFormat("en-US", moneyFormat);return (<div@@ -140,16 +151,18 @@ export function PlanCard({{primaryPrice !== null ? (<><span+ aria-label={moneyFormatter.format(primaryPrice)}className={cn("font-poppins font-medium leading-none text-zinc-800",hl ? "text-[32px]" : "text-[26px]",)}>- {formatPrice(- primaryPrice,- country.currencyCode,- country.symbol,- )}+ <NumberFlow+ value={primaryPrice}+ format={moneyFormat}+ locales="en-US"+ willChange+ /></span><span className="text-xs text-zinc-400">/ month</span></>@@ -165,30 +178,18 @@ export function PlanCard({)}</div>- {monthlyOriginal !== null &&- discountPercent !== null &&- discountPercent > 0 && (- <div className="mb-1 flex flex-wrap items-center gap-x-1.5 gap-y-0.5">- <span className="inline-flex items-center rounded-full bg-emerald-50 px-1.5 py-0.5 text-[10px] font-semibold text-emerald-700">- Save {discountPercent}%- </span>- <span className="text-xs text-zinc-500 line-through">- {formatPrice(- monthlyOriginal,- country.currencyCode,- country.symbol,- )}- </span>- </div>- )}-{chargedToday !== null && (- <div className="mb-1 text-xs font-medium text-zinc-700">- {`Charged today: ${formatPrice(- chargedToday,- country.currencyCode,- country.symbol,- )}`}+ <div+ aria-label={`Charged today: ${moneyFormatter.format(chargedToday)}`}+ className="mb-1 flex items-baseline gap-1 text-xs font-medium text-zinc-700"+ >+ <span>Charged today:</span>+ <NumberFlow+ value={chargedToday}+ format={moneyFormat}+ locales="en-US"+ willChange+ /></div>)}diff --git a/autogpt_platform/frontend/src/tests/integrations/vitest.setup.tsx b/autogpt_platform/frontend/src/tests/integrations/vitest.setup.tsxindex 04e26fa169..2efc544878 100644--- a/autogpt_platform/frontend/src/tests/integrations/vitest.setup.tsx+++ b/autogpt_platform/frontend/src/tests/integrations/vitest.setup.tsx@@ -18,6 +18,29 @@ vi.mock("react", async (importActual) => {};});+// NumberFlow renders into a shadow-DOM custom element and schedules animation+// work outside React. happy-dom can mount it, but the resulting rAF + custom+// element lifecycle collides with React 18's concurrent renderer during+// cleanup ("Should not already be working"). Render a plain span with the+// formatted value — tests query the wrapping aria-label, not NumberFlow's+// internals.+vi.mock("@number-flow/react", () => ({+ default: ({+ value,+ format,+ locales,+ }: {+ value: number;+ format?: Intl.NumberFormatOptions;+ locales?: Intl.LocalesArgument;+ }) => {+ const text = format+ ? new Intl.NumberFormat(locales ?? "en-US", format).format(value)+ : String(value);+ return <span>{text}</span>;+ },+}));+beforeAll(() => {mockNextjsModules();mockSupabaseRequest(); // If you need user's data - please mock supabase actions in your specific test - it sends null user [It's only to avoid cookies() call]