Skip to content

Commit 3f8c4f2

Browse files
committed
fix(webapp): tidy promo landing copy and bust credits cache on redeem
- omit the expiry clause on the promo page when a code has no expiry, so it no longer renders a dangling "The credits expire on ." - invalidate the promo-credits cache after a successful redeem so the usage page shows the new credits immediately instead of a stale value - align stale comment wording with redeem-at-plan-selection
1 parent 2b95f4c commit 3f8c4f2

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

apps/webapp/app/routes/promo.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
4444
return typedjson({ view: "invalid" as const, ...authMethods });
4545
}
4646

47-
// Stash the code so it survives the OAuth round-trip and can be applied when
48-
// the new org is created.
47+
// Stash the code so it survives the OAuth round-trip and can be applied once
48+
// the new org selects a plan.
4949
return typedjson(
5050
{
5151
view: "valid" as const,
@@ -152,16 +152,20 @@ export default function PromoPage() {
152152
) : (
153153
<>
154154
<Header2 className="sm:text-2xl md:text-3xl lg:text-4xl" spacing>
155-
{data.view === "valid" ? `Claim ${formatDollars(data.amountInCents)} credits` : "Create your account"}
155+
{data.view === "valid"
156+
? `Claim ${formatDollars(data.amountInCents)} credits`
157+
: "Create your account"}
156158
</Header2>
157159
{data.view === "valid" ? (
158160
<Paragraph variant="base" spacing>
159-
These are only available for new accounts. The credits expire on {formatExpiry(data.expiresAt)}.
160-
</Paragraph>
161+
These are only available for new accounts.
162+
{formatExpiry(data.expiresAt)
163+
? ` The credits expire on ${formatExpiry(data.expiresAt)}.`
164+
: ""}
165+
</Paragraph>
161166
) : (
162167
<Callout variant="warning" className="mb-6 w-full">
163-
That promo code isn't valid. You can still sign up below but credits won't be
164-
added.
168+
That promo code isn't valid. You can still sign up below but credits won't be added.
165169
</Callout>
166170
)}
167171
<SignInForm showGithubAuth={data.showGithubAuth} showGoogleAuth={data.showGoogleAuth} />

apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { prisma } from "~/db.server";
3434
import { redirectWithErrorMessage } from "~/models/message.server";
3535
import { resolveOrgIdFromSlug } from "~/models/organization.server";
3636
import { logger } from "~/services/logger.server";
37-
import { applyPromoCode, setPlan } from "~/services/platform.v3.server";
37+
import { applyPromoCode, bustPromoCreditsCache, setPlan } from "~/services/platform.v3.server";
3838
import { clearPromoCodeCookie, getPromoCodeFromCookie } from "~/services/promoCode.server";
3939
import { dashboardAction } from "~/services/routeBuilders/dashboardBuilder";
4040
import { engine } from "~/v3/runEngine.server";
@@ -166,6 +166,7 @@ export const action = dashboardAction(
166166
if (promoCode) {
167167
const applied = await applyPromoCode(organization.id, user.id, promoCode);
168168
if (applied?.applied) {
169+
bustPromoCreditsCache(organization.id);
169170
result.headers.append("Set-Cookie", await clearPromoCodeCookie());
170171
}
171172
}

apps/webapp/app/services/platform.v3.server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ export function bustBillingLimitCaches(organizationId: string) {
212212
invalidateBillingLimitCaches(organizationId);
213213
}
214214

215+
// Clear the cached promo-credits read so a just-granted code shows on the usage
216+
// page immediately rather than after the stale TTL.
217+
export function bustPromoCreditsCache(organizationId: string) {
218+
platformCache.promoCredits.remove(organizationId).catch(() => {});
219+
}
220+
215221
type Machines = typeof machinesFromPlatform;
216222

217223
const MachineOverrideValues = z.object({

0 commit comments

Comments
 (0)