Skip to content

Open source CapCut alternative.

TypeScript

fix(site): the Pro allowance promotion wiring returns to the registry, the grant and the Pro card

David Lebda895ddeb90
diff --git a/site/src/app/cut/app/(home)/settings/_components/ProCard.tsx b/site/src/app/cut/app/(home)/settings/_components/ProCard.tsx
index e637fb71..03e67449 100644
--- a/site/src/app/cut/app/(home)/settings/_components/ProCard.tsx
+++ b/site/src/app/cut/app/(home)/settings/_components/ProCard.tsx
@@ -16,18 +16,29 @@ import {
CardTitle,
} from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
-import { CUT_PRO } from "@/app/cut/_components/landing/cutPricingPlans";
+import { activeProPromotion, CUT_PRO } from "@/app/cut/_components/landing/cutPricingPlans";
import { formatDeadline, minutesLeft } from "@/cut/components/SubscribeBonusPill";
import { track } from "@/lib/analytics";
import { formatUsd } from "@/lib/credits/format-usd";
import { formatCreditExpiry } from "@/lib/credits/top-up";
import { useSubscribeBonus } from "@/queries/credits";
+import { useAccountConfig } from "@/queries/accountConfig";
+
+// The promotion's last day, the way the card names it.
+const lastDayLabel = (day: string) =>
+ new Date(`${day}T00:00:00Z`).toLocaleDateString(undefined, {
+ day: "numeric",
+ month: "long",
+ timeZone: "UTC",
+ });
export function ProCard() {
const pro = useProSubscription();
const checkout = useStartCheckout();
const portal = useOpenBillingPortal();
const bonus = useSubscribeBonus();
+ const config = useAccountConfig({ enabled: true });
+ const promotion = config.data ? activeProPromotion(config.data.settings.proAllowancePromotion) : null;
if (pro.isLoading) {
return (
@@ -61,6 +72,22 @@ export function ProCard() {
credits any time.
</CardDescription>
</CardHeader>
+ {promotion && !isActive ? (
+ <CardContent className="text-sm">
+ {promotion.lastDay !== null ? (
+ <>
+ <span className="font-medium">Get Pro by {lastDayLabel(promotion.lastDay)}</span> and every
+ month that starts by then includes ${promotion.allowanceDollars} of AI, {promotion.multiplier}× the
+ usual ${CUT_PRO.monthlyDollars}.
+ </>
+ ) : (
+ <>
+ Every month currently includes ${promotion.allowanceDollars} of AI, {promotion.multiplier}× the
+ usual ${CUT_PRO.monthlyDollars}.
+ </>
+ )}
+ </CardContent>
+ ) : null}
{isActive && data ? (
<CardContent className="text-sm text-muted-foreground">
<div className="space-y-1">
@@ -79,6 +106,13 @@ export function ProCard() {
Cancels at the end of the current period.
</div>
) : null}
+ {promotion ? (
+ <div>
+ {promotion.lastDay !== null
+ ? `Months that start by ${lastDayLabel(promotion.lastDay)} include $${promotion.allowanceDollars} of AI.`
+ : `Each new month includes $${promotion.allowanceDollars} of AI.`}
+ </div>
+ ) : null}
{offer?.status === "claimed" ? (
<div>Your {formatUsd(offer.dollars)} subscribe bonus landed in your credits.</div>
) : null}
diff --git a/site/src/lib/billing/pro-subscription.ts b/site/src/lib/billing/pro-subscription.ts
index 1ef5cdc7..4888e559 100644
--- a/site/src/lib/billing/pro-subscription.ts
+++ b/site/src/lib/billing/pro-subscription.ts
@@ -5,6 +5,8 @@ import {
stripeId,
unixToDate,
} from "@/lib/billing/stripe";
+import { promotedAllowanceMicros } from "@/lib/billing/allowance-promotion";
+import { getGlobalSetting } from "@/lib/config/effective";
import { creditMicrosPerCent, zeroCreditMicros } from "@/lib/credits/amounts";
import { grantCredits } from "@/lib/credits/inference";
import { claimSubscribeBonus, SUBSCRIBE_BONUS_METADATA_KEY } from "@/lib/credits/subscribe-bonus-claim";
@@ -97,7 +99,13 @@ export async function syncProSubscription(
const price = item?.price;
const periodStart = unixToDate(item?.current_period_start ?? null);
const periodEnd = unixToDate(item?.current_period_end ?? null);
- const allowanceMicros = allowanceMicrosFromPrice(price);
+ const allowanceMicros = periodStart
+ ? promotedAllowanceMicros(
+ allowanceMicrosFromPrice(price),
+ await getGlobalSetting("proAllowancePromotion"),
+ periodStart,
+ )
+ : allowanceMicrosFromPrice(price);
await prisma.proSubscription.upsert({
create: {
diff --git a/site/src/lib/config/registry.ts b/site/src/lib/config/registry.ts
index 0c93b9a0..e9085d3e 100644
--- a/site/src/lib/config/registry.ts
+++ b/site/src/lib/config/registry.ts
@@ -100,11 +100,28 @@ export const SETTINGS = defineSettings({
description:
"Credit offered to an account that has spent this share of its signup grant, for subscribing to Pro within the window. The credit is spendable through the last day.",
},
+ proAllowancePromotion: {
+ schema: z
+ .object({
+ // Multiplies the AI allowance a Pro billing period starts with; 1 is
+ // the plain plan.
+ multiplier: z.number().int().min(1).max(20),
+ // The last UTC day a period may start on and still get the multiplier
+ // (YYYY-MM-DD); null keeps it on for every period.
+ lastDay: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "YYYY-MM-DD").nullable(),
+ })
+ .strict(),
+ default: { multiplier: 1, lastDay: null },
+ public: true,
+ title: "Pro allowance promotion",
+ description:
+ "Multiplies the AI allowance a Pro billing period starts with, for periods that start on or before the last day. Later periods start with the plain allowance.",
+ },
});
// The settings su shows on its Product tab: what an account gets. The
// settings tab under Experiments still lists every key.
-export const PRODUCT_SETTING_KEYS = ["signupCredits", "creditExpiryNotice", "subscribeBonus"] as const satisfies readonly SettingKey[];
+export const PRODUCT_SETTING_KEYS = ["signupCredits", "creditExpiryNotice", "subscribeBonus", "proAllowancePromotion"] as const satisfies readonly SettingKey[];
export type SettingKey = keyof typeof SETTINGS;
export type Settings = SettingsOf<typeof SETTINGS>;