Skip to content

Open source CapCut alternative.

TypeScript

feat(site): onboarding names the day signup credits expire

David Lebd50849d02c1
diff --git a/site/src/app/api/account/onboarding/route.ts b/site/src/app/api/account/onboarding/route.ts
index a235286d..0e0b733a 100644
--- a/site/src/app/api/account/onboarding/route.ts
+++ b/site/src/app/api/account/onboarding/route.ts
@@ -32,6 +32,8 @@ type OnboardingState = {
// address deleted an earlier account, or the setting grants nothing. The
// credits slide names this amount.
signupCredits: string | null;
+ // When that grant stops being spendable, or null when it never does.
+ signupCreditsExpiresAt: string | null;
};
// An account that has never opened the sequence has no row; it reads as an
@@ -95,10 +97,15 @@ export const PUT = withDonkeyAuth(async (request: DonkeyAuthenticatedRequest) =>
});
async function toState(userId: string, row: OnboardingRow): Promise<OnboardingState> {
+ // The expiry is shown while it is still ahead of a live grant.
const grant = await prisma.userCreditGrant.findFirst({
where: { userId, source: "signup" },
- select: { originalAmountMicros: true },
+ select: { expiresAt: true, originalAmountMicros: true, status: true },
});
+ const expiresAt =
+ grant?.status === "active" && grant.expiresAt && grant.expiresAt > new Date()
+ ? grant.expiresAt
+ : null;
return {
version: row.version,
completedAt: row.completedAt?.toISOString() ?? null,
@@ -106,5 +113,6 @@ async function toState(userId: string, row: OnboardingRow): Promise<OnboardingSt
referralSources: row.referralSources,
referralOther: row.referralOther,
signupCredits: grant ? creditMicrosToString(grant.originalAmountMicros) : null,
+ signupCreditsExpiresAt: expiresAt?.toISOString() ?? null,
};
}
diff --git a/site/src/cut/components/onboarding/CutOnboarding.tsx b/site/src/cut/components/onboarding/CutOnboarding.tsx
index 76cde2a7..34a06d11 100644
--- a/site/src/cut/components/onboarding/CutOnboarding.tsx
+++ b/site/src/cut/components/onboarding/CutOnboarding.tsx
@@ -338,7 +338,10 @@ export function CutOnboarding() {
)}
{step === 2 && <ModesSlide />}
{step === 3 && (
- <CreditsSlide credits={state?.signupCredits ?? null} />
+ <CreditsSlide
+ credits={state?.signupCredits ?? null}
+ expiresAt={state?.signupCreditsExpiresAt ?? null}
+ />
)}
{step === 4 && <AiChatSlide />}
{step === 5 && !isPro && <PlansSlide onSkipPro={() => finish(false)} />}
diff --git a/site/src/cut/components/onboarding/slides/Credits.tsx b/site/src/cut/components/onboarding/slides/Credits.tsx
index e8933ab0..6f3e376c 100644
--- a/site/src/cut/components/onboarding/slides/Credits.tsx
+++ b/site/src/cut/components/onboarding/slides/Credits.tsx
@@ -3,6 +3,7 @@
import { useEffect, useRef } from "react";
import { burstConfetti } from "@/cut/components/onboarding/confetti";
+import { formatCreditExpiry } from "@/lib/credits/top-up";
// The signup grant already landed when the account was created, so this slide
// never grants anything — it says what's there: the USD the grant carried, read
@@ -10,8 +11,15 @@ import { burstConfetti } from "@/cut/components/onboarding/confetti";
// don't change between them; the burst fires every time the slide is reached.
// An account with no grant — its address already had one on an earlier,
// deleted account, or the signup-credits setting grants nothing — gets the
-// slide without an amount.
-export function CreditsSlide({ credits }: { credits: string | null }) {
+// slide without an amount. A grant with an expiry names the date under the
+// amount.
+export function CreditsSlide({
+ credits,
+ expiresAt,
+}: {
+ credits: string | null;
+ expiresAt: string | null;
+}) {
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
@@ -65,6 +73,11 @@ export function CreditsSlide({ credits }: { credits: string | null }) {
Already in your account — nothing to claim. Spend it on generated
video, audio and images.
</p>
+ {expiresAt !== null && (
+ <p className="mt-3 text-[13px] leading-[1.5] text-[#8a8a8a]">
+ Expires {formatCreditExpiry(new Date(expiresAt))}.
+ </p>
+ )}
</div>
</div>
);
diff --git a/site/src/lib/credits/top-up.ts b/site/src/lib/credits/top-up.ts
index 8571088a..d63236bf 100644
--- a/site/src/lib/credits/top-up.ts
+++ b/site/src/lib/credits/top-up.ts
@@ -44,3 +44,8 @@ export function creditGrantExpiry(expiresAfterDays: number | null, now = new Dat
if (expiresAfterDays === null) return undefined;
return new Date(now.getTime() + expiresAfterDays * 24 * 60 * 60 * 1000);
}
+
+/** The expiry as people read it: "September 14, 2026". */
+export function formatCreditExpiry(expiresAt: Date): string {
+ return expiresAt.toLocaleDateString("en-US", { day: "numeric", month: "long", year: "numeric" });
+}
diff --git a/site/src/queries/onboarding.ts b/site/src/queries/onboarding.ts
index 534f1d02..9e7f15c7 100644
--- a/site/src/queries/onboarding.ts
+++ b/site/src/queries/onboarding.ts
@@ -14,6 +14,7 @@ export type OnboardingState = {
referralSources: string[];
referralOther: string | null;
signupCredits: string | null;
+ signupCreditsExpiresAt: string | null;
};
type OnboardingUpdate =