core: credit referral invites on first Lite checkout

Applies saved invites during Lite checkout so users who skip the referral page still credit the inviter. Avoids crediting already-active Lite workspaces so rewards stay tied to the first upgrade.
This commit is contained in:
vimtor 2026-05-30 10:52:21 +02:00
commit 6a2cd816b7
No known key found for this signature in database
4 changed files with 35 additions and 22 deletions

View file

@ -15,6 +15,7 @@ import { useI18n } from "~/context/i18n"
import { useLanguage } from "~/context/language"
import { formError } from "~/lib/form-error"
import { formatResetTime, liteResetTimeKeys } from "~/lib/format-reset-time"
import { createReferralFromCookie } from "~/lib/referral-invite"
import { IconAlipay, IconUpi } from "~/component/icon"
@ -75,15 +76,16 @@ const createLiteCheckoutUrl = action(
"use server"
return json(
await withActor(
() =>
Billing.generateLiteCheckoutUrl({ successUrl, cancelUrl, method })
.then((data) => ({ error: undefined, data }))
.catch((e) => ({
error: e.message as string,
data: undefined,
})),
async () => {
const data = await Billing.generateLiteCheckoutUrl({ successUrl, cancelUrl, method })
await createReferralFromCookie()
return { error: undefined, data }
},
workspaceID,
),
).catch((e) => ({
error: e.message as string,
data: undefined,
})),
{ revalidate: [queryBillingInfo.key, queryLiteSubscription.key] },
)
},