Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Label early supporters on the billing page (#3309)
Luke Vella202d76bda400
diff --git a/apps/web/biome.json b/apps/web/biome.jsonindex 59257228b..30b695ac1 100644--- a/apps/web/biome.json+++ b/apps/web/biome.json@@ -296,7 +296,6 @@"src/app/*/(space)/(dashboard)/layout.tsx","src/app/*/(space)/settings/api-keys/components/api-keys-list.tsx","src/app/*/(space)/settings/api-keys/page.tsx",- "src/app/*/(space)/settings/billing/page.tsx","src/app/*/(space)/settings/profile/components/account-deletion-summary.tsx","src/app/*/(space)/settings/security/page.tsx","src/app/*/(space)/settings/spaces/page.tsx",diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 68524c489..dc8c25104 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -277,6 +277,10 @@"durationHoursMinutes": "{hours, plural, one {#h} other {#h}} {minutes, plural, one {#m} other {#m}}","durationLabel": "Duration","durationMinutes": "{count, plural, one {#m} other {#m}}",+ "earlySupporter": "Early supporter",+ "earlySupporterRateEnds": "Your early supporter rate ends with your subscription. New subscriptions are {price} per {interval, select, month {month} other {year}}.",+ "earlySupporterRateEndsNoPrice": "Your early supporter rate ends with your subscription.",+ "earlySupporterRateKept": "You keep this rate for as long as your subscription stays active.","edit": "Edit","editDetails": "Edit details","editDetailsDescription": "Change the details of your event.",diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.test.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.test.tsxindex 2806480a9..72804a7d8 100644--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.test.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.test.tsx@@ -35,6 +35,8 @@ const baseProps = {status: "active" as const,cancelAtPeriodEnd: false,periodEnd: new Date("2026-01-01T00:00:00Z"),+ earlySupporter: false,+ listPrice: null,};describe("ProPlanCard", () => {@@ -70,4 +72,30 @@ describe("ProPlanCard", () => {expect(screen.getByText("$16.00")).toHaveClass("line-through");expect(screen.getByText(/discount applied/)).toBeInTheDocument();});++ it("labels early supporters and says the rate is kept", () => {+ render(<ProPlanCard {...baseProps} earlySupporter listPrice={null} />);++ expect(screen.getByText("Early supporter")).toBeInTheDocument();+ expect(document.querySelector(".line-through")).toBeNull();+ });++ it("shows nothing about early supporters on a current price", () => {+ render(<ProPlanCard {...baseProps} />);++ expect(screen.queryByText("Early supporter")).not.toBeInTheDocument();+ });++ it("keeps the badge when cancellation is scheduled", () => {+ render(+ <ProPlanCard+ {...baseProps}+ earlySupporter+ cancelAtPeriodEnd+ listPrice={{ monthly: 1000, yearly: 8400 }}+ />,+ );++ expect(screen.getByText("Early supporter")).toBeInTheDocument();+ });});diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsxindex a7b2158b8..d154f5018 100644--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx@@ -5,11 +5,13 @@ import { Button } from "@rallly/ui/button";import { DialogTrigger } from "@rallly/ui/dialog";import { ArmchairIcon, CreditCardIcon, DotIcon } from "lucide-react";import { openCustomerPortalAction } from "@/features/billing/actions";+import { EarlySupporterBadge } from "@/features/billing/components/early-supporter-badge";import { SubscriptionStatusBadge } from "@/features/billing/components/subscription-status-badge";import type {BillingInterval,SubscriptionStatus,} from "@/features/billing/schema";+import { formatMinorUnitAmount } from "@/features/billing/utils";import {SpaceTierIcon,SpaceTierLabel,@@ -42,6 +44,8 @@ export function ProPlanCard({status,cancelAtPeriodEnd,periodEnd,+ earlySupporter,+ listPrice,className,}: {amount: number;@@ -54,6 +58,8 @@ export function ProPlanCard({status: SubscriptionStatus;cancelAtPeriodEnd: boolean;periodEnd: Date;+ earlySupporter: boolean;+ listPrice: { monthly?: number; yearly?: number } | null;className?: string;}) {const { locale } = useDateTimeConfig();@@ -61,10 +67,7 @@ export function ProPlanCard({const openCustomerPortal = useSafeAction(openCustomerPortalAction);const formatCurrency = (minorUnitAmount: number) =>- new Intl.NumberFormat(locale, {- style: "currency",- currency: currency.toUpperCase(),- }).format(minorUnitAmount / 100);+ formatMinorUnitAmount({ amount: minorUnitAmount, currency, locale });// amount is the per-seat unit amount in the currency's minor unit. Coupons// and promotion codes are applied by Stripe at the invoice level, so we apply@@ -86,6 +89,8 @@ export function ProPlanCard({const date = formatDateTime(periodEnd, "date");const endsAtPeriodEnd = status === "canceled" || cancelAtPeriodEnd;+ const listPriceForInterval =+ listPrice?.[interval === "month" ? "monthly" : "yearly"];return (<PlanCard className={className}>@@ -99,6 +104,32 @@ export function ProPlanCard({<SpaceTierLabel tier="pro" /></PlanCardTitle><SubscriptionStatusBadge status={status} />+ {earlySupporter ? (+ <EarlySupporterBadge>+ {endsAtPeriodEnd ? (+ listPriceForInterval !== undefined ? (+ <Trans+ i18nKey="earlySupporterRateEnds"+ defaults="Your early supporter rate ends with your subscription. New subscriptions are {price} per {interval, select, month {month} other {year}}."+ values={{+ price: formatCurrency(listPriceForInterval),+ interval,+ }}+ />+ ) : (+ <Trans+ i18nKey="earlySupporterRateEndsNoPrice"+ defaults="Your early supporter rate ends with your subscription."+ />+ )+ ) : (+ <Trans+ i18nKey="earlySupporterRateKept"+ defaults="You keep this rate for as long as your subscription stays active."+ />+ )}+ </EarlySupporterBadge>+ ) : null}</div><PlanCardDescription className="flex items-center"><Transdiff --git a/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/page.tsxindex b7f44dc0e..c089f911c 100644--- a/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx@@ -24,7 +24,7 @@ import {SettingsPageTitle,} from "@/components/settings-layout";import { BillingFlashAlert } from "@/features/billing/components/billing-flash-alert";-import { getSpaceSubscription } from "@/features/billing/data";+import { loadSubscriptionOverview } from "@/features/billing/loaders";import { getActiveSpace, getSeatUsage } from "@/features/space/loaders";import { defineAbilityForMember } from "@/features/space/member/ability";import { requireUser } from "@/features/user/loaders";@@ -68,8 +68,8 @@ export default async function BillingSettingsPage() {);}- const [subscription, seatUsage] = await Promise.all([- getSpaceSubscription(space.id),+ const [overview, seatUsage] = await Promise.all([+ loadSubscriptionOverview(),getSeatUsage(),]);@@ -101,18 +101,20 @@ export default async function BillingSettingsPage() {</PageSectionDescription></PageSectionHeader><PageSectionContent>- {subscription?.active ? (+ {overview?.subscription.active ? (<ProPlanCard- amount={subscription.amount}- discountPercentOff={subscription.discountPercentOff}- discountAmountOff={subscription.discountAmountOff}- currency={subscription.currency}- interval={subscription.interval}- seats={subscription.quantity}+ amount={overview.subscription.amount}+ discountPercentOff={overview.subscription.discountPercentOff}+ discountAmountOff={overview.subscription.discountAmountOff}+ currency={overview.subscription.currency}+ interval={overview.subscription.interval}+ seats={overview.subscription.quantity}usedSeats={seatUsage.used}- status={subscription.status}- cancelAtPeriodEnd={subscription.cancelAtPeriodEnd}- periodEnd={subscription.periodEnd}+ status={overview.subscription.status}+ cancelAtPeriodEnd={overview.subscription.cancelAtPeriodEnd}+ periodEnd={overview.subscription.periodEnd}+ earlySupporter={overview.earlySupporter}+ listPrice={overview.listPrice}/>) : (<HobbyPlanCard />diff --git a/apps/web/src/features/billing/components/early-supporter-badge.tsx b/apps/web/src/features/billing/components/early-supporter-badge.tsxnew file mode 100644index 000000000..e82094d6a--- /dev/null+++ b/apps/web/src/features/billing/components/early-supporter-badge.tsx@@ -0,0 +1,26 @@+"use client";++import { Badge } from "@rallly/ui/badge";+import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";+import { BirdIcon } from "lucide-react";+import type * as React from "react";+import { Trans } from "@/i18n/client";++export function EarlySupporterBadge({+ children,+}: {+ /** Tooltip content explaining what the rate means for this subscriber. */+ children: React.ReactNode;+}) {+ return (+ <Tooltip>+ <TooltipTrigger+ render={<Badge tabIndex={0} variant="pink" className="gap-1" />}+ >+ <BirdIcon className="size-3" />+ <Trans i18nKey="earlySupporter" defaults="Early supporter" />+ </TooltipTrigger>+ <TooltipContent className="max-w-xs">{children}</TooltipContent>+ </Tooltip>+ );+}diff --git a/apps/web/src/features/billing/loaders.ts b/apps/web/src/features/billing/loaders.tsindex c5c10c45b..f27d4115d 100644--- a/apps/web/src/features/billing/loaders.ts+++ b/apps/web/src/features/billing/loaders.ts@@ -1,10 +1,14 @@import "server-only";+import type { PricingData } from "@rallly/billing";import { CURRENCY_COOKIE_NAME, getCountryCurrency } from "@rallly/billing";import { cookies, headers } from "next/headers";import { cache } from "react";import { isBillingEnabled } from "@/features/billing/constants";-import { getProPrices } from "@/features/billing/data";+import { getProPrices, getSpaceSubscription } from "@/features/billing/data";+import { isEarlySupporter } from "@/features/billing/utils";+import { getActiveSpace } from "@/features/space/loaders";+import { getCurrentUser } from "@/features/user/loaders";/*** Prices for the pay wall plus the currency to show first: the currency the@@ -45,3 +49,46 @@ export const loadPayWallPricing = cache(async () => {return null;}});++/**+ * Everything the billing page needs about the active space's subscription,+ * with the early supporter verdict made here so no page compares price ids.+ * Pricing failures degrade to "not an early supporter, no comparison" rather+ * than failing the page.+ */+export const loadSubscriptionOverview = cache(async () => {+ const [user, space] = await Promise.all([getCurrentUser(), getActiveSpace()]);+ const subscription = await getSpaceSubscription(space.id);++ if (!subscription) {+ return null;+ }++ let pricing: PricingData | null = null;+ try {+ pricing = await getProPrices();+ } catch (error) {+ console.error("Failed to load Pro pricing", error);+ }++ const earlySupporter = isEarlySupporter({+ priceId: subscription.priceId,+ pricing,+ });+ const currency = subscription.currency;++ return {+ subscription,+ earlySupporter,+ listPrice: pricing+ ? {+ monthly: pricing.monthly.amounts[currency],+ yearly: pricing.yearly.amounts[currency],+ }+ : null,+ // The deletion recovery window reaps the space regardless of renewal;+ // resuming there would fight the reaper, so cancelling the deletion is+ // the only way to restore renewals.+ canResume: subscription.cancelAtPeriodEnd && !user?.deletedAt,+ };+});diff --git a/apps/web/src/features/billing/utils.test.ts b/apps/web/src/features/billing/utils.test.tsindex 675961eba..e4702a507 100644--- a/apps/web/src/features/billing/utils.test.ts+++ b/apps/web/src/features/billing/utils.test.ts@@ -1,5 +1,9 @@import { afterEach, describe, expect, it, vi } from "vitest";-import { isEarlySupporter, resolvePriceSet } from "./utils";+import {+ formatMinorUnitAmount,+ isEarlySupporter,+ resolvePriceSet,+} from "./utils";// isBillingEnabled is a module constant read from the environment, so each// branch needs a fresh module registry to observe the stubbed value.@@ -97,3 +101,17 @@ describe("resolvePriceSet", () => {).toEqual({ monthly: pricing.monthly, yearly: pricing.yearly });});});++describe("formatMinorUnitAmount", () => {+ it("formats minor units as a localized currency string", () => {+ expect(+ formatMinorUnitAmount({ amount: 5600, currency: "usd", locale: "en" }),+ ).toBe("$56.00");+ });++ it("does not scale zero decimal currencies", () => {+ expect(+ formatMinorUnitAmount({ amount: 5600, currency: "jpy", locale: "en" }),+ ).toBe("¥5,600");+ });+});diff --git a/apps/web/src/features/billing/utils.ts b/apps/web/src/features/billing/utils.tsindex 65900de73..31edca66e 100644--- a/apps/web/src/features/billing/utils.ts+++ b/apps/web/src/features/billing/utils.ts@@ -57,3 +57,23 @@ export function resolvePriceSet({}return { monthly: pricing.monthly, yearly: pricing.yearly };}++export function formatMinorUnitAmount({+ amount,+ currency,+ locale,+}: {+ amount: number;+ currency: string;+ locale: string;+}) {+ const formatter = new Intl.NumberFormat(locale, {+ style: "currency",+ currency: currency.toUpperCase(),+ });+ // Stripe amounts are in the currency's minor unit, which Intl knows: two+ // fraction digits for most currencies, none for JPY and friends.+ const minorUnitDigits =+ formatter.resolvedOptions().maximumFractionDigits ?? 2;+ return formatter.format(amount / 10 ** minorUnitDigits);+}diff --git a/packages/ui/src/badge.tsx b/packages/ui/src/badge.tsxindex c91870eda..1cf66eb05 100644--- a/packages/ui/src/badge.tsx+++ b/packages/ui/src/badge.tsx@@ -16,6 +16,7 @@ const badgeVariants = cva(outline: "text-foreground",green:"bg-green-400/10 text-green-600 dark:bg-green-500/10 dark:text-green-500",+ pink: "bg-pink-400/10 text-pink-600 dark:bg-pink-500/10 dark:text-pink-400",secondary: "bg-primary/10 text-primary",pill: "rounded-full bg-gray-200 text-gray-700 dark:bg-gray-700 dark:text-gray-200",},