Open source CapCut alternative.
TypeScript
feat(site): the onboarding credits slide reads whether the grant landed
David Leb5fbd5442825
diff --git a/site/src/app/api/account/onboarding/route.ts b/site/src/app/api/account/onboarding/route.tsindex 0f26bdf2..855d19f0 100644--- a/site/src/app/api/account/onboarding/route.ts+++ b/site/src/app/api/account/onboarding/route.ts@@ -13,17 +13,29 @@ import {} from "@/lib/onboarding/sequence";import { prisma } from "@/lib/prisma";+type OnboardingRow = {+ version: number;+ completedAt: Date | null;+ skipped: boolean;+ referralSources: string[];+ referralOther: string | null;+};+type OnboardingState = {version: number;completedAt: string | null;skipped: boolean;referralSources: string[];referralOther: string | null;+ // Whether the signup credit grant landed on this account. An address that+ // deleted an earlier account starts without it, and the credits slide says+ // so.+ signupCreditsGranted: boolean;};// An account that has never opened the sequence has no row; it reads as an// unfinished run of the current sequence rather than as an error.-const UNSTARTED: OnboardingState = {+const UNSTARTED: OnboardingRow = {version: ONBOARDING_VERSION,completedAt: null,skipped: false,@@ -32,10 +44,9 @@ const UNSTARTED: OnboardingState = {};export const GET = withDonkeyAuth(async (request: DonkeyAuthenticatedRequest) => {- const row = await prisma.userOnboarding.findUnique({- where: { userId: request.donkey.userId },- });- return NextResponse.json(row ? toState(row) : UNSTARTED);+ const userId = request.donkey.userId;+ const row = await prisma.userOnboarding.findUnique({ where: { userId } });+ return NextResponse.json(await toState(userId, row ?? UNSTARTED));});const updateSchema = z@@ -79,21 +90,20 @@ export const PUT = withDonkeyAuth(async (request: DonkeyAuthenticatedRequest) =>create: { userId, version: ONBOARDING_VERSION, ...data },update: data,});- return NextResponse.json(toState(row));+ return NextResponse.json(await toState(userId, row));});-function toState(row: {- version: number;- completedAt: Date | null;- skipped: boolean;- referralSources: string[];- referralOther: string | null;-}): OnboardingState {+async function toState(userId: string, row: OnboardingRow): Promise<OnboardingState> {+ const grant = await prisma.userCreditGrant.findFirst({+ where: { userId, source: "signup" },+ select: { id: true },+ });return {version: row.version,completedAt: row.completedAt?.toISOString() ?? null,skipped: row.skipped,referralSources: row.referralSources,referralOther: row.referralOther,+ signupCreditsGranted: grant !== null,};}diff --git a/site/src/cut/components/onboarding/CutOnboarding.tsx b/site/src/cut/components/onboarding/CutOnboarding.tsxindex 795a9993..19dfc4cf 100644--- a/site/src/cut/components/onboarding/CutOnboarding.tsx+++ b/site/src/cut/components/onboarding/CutOnboarding.tsx@@ -337,7 +337,9 @@ export function CutOnboarding() {/>)}{step === 2 && <ModesSlide />}- {step === 3 && <CreditsSlide />}+ {step === 3 && (+ <CreditsSlide granted={state?.signupCreditsGranted ?? true} />+ )}{step === 4 && <AiChatSlide />}{step === 5 && !isPro && <PlansSlide onSkipPro={() => finish(false)} />}</div>diff --git a/site/src/cut/components/onboarding/slides/Credits.tsx b/site/src/cut/components/onboarding/slides/Credits.tsxindex 4a9ad412..027a093a 100644--- a/site/src/cut/components/onboarding/slides/Credits.tsx+++ b/site/src/cut/components/onboarding/slides/Credits.tsx@@ -8,15 +8,33 @@ import { signupAppCredits } from "@/lib/onboarding/sequence";// The signup grant already landed when the account was created, so this slide// never grants anything — it says what's there. That's as true on a replay as// on a first run, so the words don't change between them; the burst fires every-// time the slide is reached.-export function CreditsSlide() {+// time the slide is reached. An account whose address already received the+// grant on an earlier, deleted account has none, and the slide says that.+export function CreditsSlide({ granted }: { granted: boolean }) {const canvasRef = useRef<HTMLCanvasElement>(null);useEffect(() => {const canvas = canvasRef.current;if (!canvas) return;+ if (!granted) return;return burstConfetti(canvas);- }, []);+ }, [granted]);++ if (!granted) {+ return (+ <div className="relative flex flex-col items-center text-center">+ <div className="relative max-w-[900px]">+ <h2 className="text-[clamp(26px,4.4vw,52px)] font-light leading-[1.02] tracking-[-0.03em]">+ Welcome back+ </h2>+ <p className="mx-auto mt-4 max-w-[460px] text-left text-[16px] leading-[1.55] text-[#454545]">+ Signup credits came with your first account. Top up or go Pro to+ generate video, audio and images.+ </p>+ </div>+ </div>+ );+ }return (<div className="relative flex flex-col items-center text-center">diff --git a/site/src/queries/onboarding.ts b/site/src/queries/onboarding.tsindex 7438a74f..deea5f0b 100644--- a/site/src/queries/onboarding.ts+++ b/site/src/queries/onboarding.ts@@ -13,6 +13,7 @@ export type OnboardingState = {skipped: boolean;referralSources: string[];referralOther: string | null;+ signupCreditsGranted: boolean;};type OnboardingUpdate =