Skip to content

Open source CapCut alternative.

TypeScript

feat(site): a credit offer's claim link closes three days after the send

David Le06bd3a0abbd1
diff --git a/AGENTS.md b/AGENTS.md
index f259b2d0..f384acc2 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -46,7 +46,7 @@ Every Cut change has to hold on all four surfaces, and the plan for it says how:
- Do not touch repository-root `prototype/` unless the user explicitly asks for that filesystem path. By default, assume requested product changes are for the Mac app or the site/landing page.
- Ask before creating any new plan document.
- Code reviews run on the latest Opus model; fixes and implementation run on the latest Fable model. Make the switch yourself: a review request (`/review`, "review this") runs in the `code-reviewer` agent (`.claude/agents/code-reviewer.md`, which pins `model: opus`) whatever the session model is, and a fix runs on Fable, spawned in an agent with `model: "fable"` when the session is on something else. A forked skill runs on the session model, so a review never goes through a fork. Never ask the user to `/model`.
-- When writing or editing any engineering doc under `docs/`, follow `docs/guides/eng-doc-style.md`.
+- All writing follows `docs/guides/writing-style.md`: docs, guides, articles and blog posts, landing page and marketing copy, release notes, emails, UI copy, commit messages, code comments, and chat replies. The voice is a thoughtful engineer explaining what they learned while building real software: conversational, calm, precise, why before what, concrete examples, starting from a real problem. Engineering docs under `docs/` also follow the structure in `docs/guides/eng-doc-style.md`.
- Write straight up — in prompts, docs, commits, code comments, summaries, and UI copy. State what a thing is, once, and stop. Never frame it against what it is not: no "X, not Y", no "X rather than Y", no "instead of Z", no "…, which is exactly what not to do". Cut filler.
- Keep replies short and action-oriented. For implementation questions, give the recommendation first, then one to three short bullets on why; when the answer is obvious, just say what to do. Skip long explanations, caveats, and "one last thing" sections; flag a real blocker or risk with "One issue:" and explain it briefly.
- Never dress a fact up as an aside. No "worth knowing", "worth flagging", "worth calling out", "one thing to note", "for future reference", "the part that matters here" — and no other phrase that announces information as bonus insight. This holds anywhere in a reply, not just at the end. If it matters, state it plainly as part of the work; if it does not, cut it. A problem gets fixed in the same turn it is found, and anything that changes what the user does belongs in the body of the summary, said once.
diff --git a/CLAUDE.md b/CLAUDE.md
index f259b2d0..f384acc2 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -46,7 +46,7 @@ Every Cut change has to hold on all four surfaces, and the plan for it says how:
- Do not touch repository-root `prototype/` unless the user explicitly asks for that filesystem path. By default, assume requested product changes are for the Mac app or the site/landing page.
- Ask before creating any new plan document.
- Code reviews run on the latest Opus model; fixes and implementation run on the latest Fable model. Make the switch yourself: a review request (`/review`, "review this") runs in the `code-reviewer` agent (`.claude/agents/code-reviewer.md`, which pins `model: opus`) whatever the session model is, and a fix runs on Fable, spawned in an agent with `model: "fable"` when the session is on something else. A forked skill runs on the session model, so a review never goes through a fork. Never ask the user to `/model`.
-- When writing or editing any engineering doc under `docs/`, follow `docs/guides/eng-doc-style.md`.
+- All writing follows `docs/guides/writing-style.md`: docs, guides, articles and blog posts, landing page and marketing copy, release notes, emails, UI copy, commit messages, code comments, and chat replies. The voice is a thoughtful engineer explaining what they learned while building real software: conversational, calm, precise, why before what, concrete examples, starting from a real problem. Engineering docs under `docs/` also follow the structure in `docs/guides/eng-doc-style.md`.
- Write straight up — in prompts, docs, commits, code comments, summaries, and UI copy. State what a thing is, once, and stop. Never frame it against what it is not: no "X, not Y", no "X rather than Y", no "instead of Z", no "…, which is exactly what not to do". Cut filler.
- Keep replies short and action-oriented. For implementation questions, give the recommendation first, then one to three short bullets on why; when the answer is obvious, just say what to do. Skip long explanations, caveats, and "one last thing" sections; flag a real blocker or risk with "One issue:" and explain it briefly.
- Never dress a fact up as an aside. No "worth knowing", "worth flagging", "worth calling out", "one thing to note", "for future reference", "the part that matters here" — and no other phrase that announces information as bonus insight. This holds anywhere in a reply, not just at the end. If it matters, state it plainly as part of the work; if it does not, cut it. A problem gets fixed in the same turn it is found, and anything that changes what the user does belongs in the body of the summary, said once.
diff --git a/docs/README.md b/docs/README.md
index d915ce0f..cabcd82c 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -35,9 +35,10 @@ Supported product and engineering guides live in `docs/guides/`. This list is th
- [Swift Guide](guides/swift.md) — the MVC split, language defaults, concurrency, SwiftUI, Mac platform behavior, data, and tests for the iOS and Mac apps.
- [Code Review Guide](guides/code-review.md) — what makes a change reviewable, and how we review.
+- [Writing Style](guides/writing-style.md) — the one voice for everything we write: docs, articles, marketing, UI copy, commits, and chat.
- [Engineering Doc Style Guide](guides/eng-doc-style.md) — the required structure, sentence-level rules, and post-writing test for every doc here.
-Add or update an entry here when behavior becomes supported. Don't duplicate this index in subdirectories or app folders; link directly between related docs only when the relationship helps a maintainer. Write and edit docs following the [Engineering Doc Style Guide](guides/eng-doc-style.md).
+Add or update an entry here when behavior becomes supported. Don't duplicate this index in subdirectories or app folders; link directly between related docs only when the relationship helps a maintainer. Write in the voice of the [Writing Style](guides/writing-style.md) guide, and structure docs following the [Engineering Doc Style Guide](guides/eng-doc-style.md).
## Navigation Rules
diff --git a/docs/guides/config-and-experiments.md b/docs/guides/config-and-experiments.md
index 8f27d770..aa672fc3 100644
--- a/docs/guides/config-and-experiments.md
+++ b/docs/guides/config-and-experiments.md
@@ -136,7 +136,8 @@ A credit promotion is a credit offer: one row that promises an account an
amount, the credit's life, and the window it can be claimed in, then records
the grant that lands. Every kind shares that row, and a kind is a setting and
code: what opens the offer and what claims it. The manual credit su sends by
-email is one kind; the subscribe bonus, offered when an account has spent a
+email is one kind, and its link closes a few days after the send, a Product-tab
+setting; the subscribe bonus, offered when an account has spent a
share of its signup grant and landed by a Pro subscription created inside the
window, is another. A new promotion adds no table.
diff --git a/docs/guides/eng-doc-style.md b/docs/guides/eng-doc-style.md
index bb58e485..91398d39 100644
--- a/docs/guides/eng-doc-style.md
+++ b/docs/guides/eng-doc-style.md
@@ -3,6 +3,8 @@
How to write the docs in this repo: architecture notes, runtime specs,
contributor guides — anything a teammate or a coding agent reads once and then
has to follow. Lead with the point, keep it short, and write like a person.
+The voice is the one in the [Writing Style](writing-style.md) guide; this doc
+adds the structure an engineering doc needs on top of it.
## Principles
diff --git a/docs/guides/writing-style.md b/docs/guides/writing-style.md
new file mode 100644
index 00000000..eed5efcf
--- /dev/null
+++ b/docs/guides/writing-style.md
@@ -0,0 +1,117 @@
+# Writing Style
+
+How everything from Donkey reads: docs, guides, blog posts and articles, landing
+page and marketing copy, release notes, emails, UI copy, commit messages, and
+what the assistant says in chat. One voice everywhere.
+
+**The one rule:** write like a thoughtful engineer explaining something they
+learned while building real software, to a peer, out loud. Calm, curious,
+precise, and simple without being dumbed down.
+
+## The Voice
+
+The reader is a smart person who was not in the room. The writing brings them
+into the room. It walks them from the problem to the model to the answer, so
+that by the end they understand *why* the system behaves the way it does, and
+could rederive the answer themselves.
+
+That shape holds whether the piece is a two-thousand-word article or a
+one-line tooltip. The article walks the whole path. The tooltip says the one
+true thing the path ends at.
+
+- **Conversational and calm.** Plain words, first person where it fits, no
+ drama. The tone of someone who has already solved it and is now thinking it
+ through for you.
+- **Technically precise.** Every claim is one you could check. Name the actual
+ mechanism. If the number matters, give the number.
+- **Curious over authoritative.** "Here is what I noticed, here is why I think
+ it happens, here is what that implies." Reasoning in the open. The reader
+ gets to disagree with a step.
+- **Why before what.** A rule without its reason gets misapplied the first time
+ the situation shifts. Explain the reason and the rule follows.
+- **Concrete.** A real problem, a real example, a small piece of code where it
+ helps. One specific case beats three general statements.
+
+## The Shape of a Piece
+
+Start with a real problem or observation. Something that happened, something
+that was surprising, a question a colleague asked. The first sentence already
+has content in it.
+
+Build a mental model from first principles. What are the parts, what does each
+one know, what constraint is each one under. Keep it small. A model with three
+moving pieces that the reader can hold in their head beats a complete one they
+cannot.
+
+Use the model to explain the solution. The fix should feel inevitable once the
+model is in place. If it does not, the model is missing a piece.
+
+Say what the tradeoffs are. What the solution gives up, when it stops being the
+right call, what you would watch for. This is where the reader learns to trust
+you.
+
+Stop when the content stops. No wrap-up paragraph, no restated conclusion, no
+offer of more.
+
+```text
+observation → model → solution → tradeoffs → stop
+```
+
+## Sentences
+
+- Short sentences carry rules. Longer ones carry the why. A sentence past
+ twenty words is usually two.
+- Active voice with a named actor. "The engine watches the parent process"
+ beats "the parent process is watched."
+- State what a thing is, then stop. Never frame it against what it is not. Cut
+ every "X, not Y", "X rather than Y", "X instead of Z". If the reader would
+ not have assumed Y, naming Y teaches them a wrong idea on the way to the
+ right one.
+- Say it straight, with the strong verb. "Adapters never hold task state"
+ beats "adapters should generally avoid holding task state."
+- Prose is the default. Headings and bullets appear when the content really is
+ a list or really does change subject. A run of three bullets that could be
+ one paragraph is one paragraph.
+- Code font only for what someone will type or read in a file. Describe tools,
+ types, and paths in words.
+
+## Cut
+
+- Marketing language. "Powerful", "seamless", "blazing fast", "effortless",
+ "delightful". If the thing is fast, say how fast and why.
+- Generic openings. "In this article we will", "in today's world", "have you
+ ever wondered". The first sentence has content in it.
+- Announcements of what the writing is about to do. "Let's dive in", "let's
+ break this down", "now let's look at".
+- Filler that signals insight. "Worth noting", "it's important to understand",
+ "the key takeaway is", "at the end of the day". If it matters, say it. If it
+ does not, cut it.
+- Repetitive summaries. A closing paragraph that restates the piece. A
+ "conclusion" heading. A "TL;DR" for something the intro already led with.
+- Jargon that plain words cover. Coined names, internal acronyms, and file
+ paths go stale and read as noise.
+- Hedges on things you know. "Might", "could potentially", "in some cases" when
+ it is simply true.
+- Corporate polish. Every sentence the same length, every paragraph three
+ sentences, every idea in a bullet. Let it breathe unevenly, like a person.
+- Rhetorical questions the next sentence answers. Ask the question because you
+ do not know, or state the answer.
+
+## Where It Applies
+
+| Surface | What it looks like |
+| --- | --- |
+| Articles and blog posts | The full path: observation, model, solution, tradeoffs. Small code where it helps. |
+| Engineering docs and guides | Same voice, with the structure in the [Engineering Doc Style Guide](eng-doc-style.md): lead with the point, name the invariants, facts in tables. |
+| Landing page and marketing | The problem in the reader's words, then what Donkey does about it, in the same calm voice. No superlatives. The proof is the specific. |
+| Release notes and emails | What changed and why someone would care, in one or two plain sentences each. |
+| UI copy and tooltips | The one true thing, in the fewest plain words. |
+| Commit messages and code comments | What the change does and why, as a peer would explain it in review. |
+| The assistant in chat | Recommendation first, then the why. Same calm, same precision. |
+
+## Before You Ship It
+
+1. Does the first sentence have something in it?
+2. Could the reader explain *why* it works, without you there?
+3. Is there a sentence a marketing team would have written? Cut it.
+4. Does it stop when the content stops?
diff --git a/site/src/app/api/credits/offers/claim/route.ts b/site/src/app/api/credits/offers/claim/route.ts
index aacd7d83..4c91ddeb 100644
--- a/site/src/app/api/credits/offers/claim/route.ts
+++ b/site/src/app/api/credits/offers/claim/route.ts
@@ -6,7 +6,9 @@ import { formatUsdPlain } from "@/lib/credits/format-usd";
import { getCreditBalance } from "@/lib/credits/inference";
import {
claimCreditOffer,
+ CreditOfferClosedError,
CreditOfferNotYoursError,
+ creditOfferOpen,
MANUAL_OFFER_KIND,
verifyCreditOfferToken,
} from "@/lib/credits/offers";
@@ -19,18 +21,22 @@ const claimRequestSchema = z.object({ token: z.string().min(1) }).strict();
// Describes the offer a claim link names, for the dialog that presents it.
// The token proves the link came from the offer's email; the session has to be
// the offered account's, and a different account is told so before it tries.
+// An offer whose claim window closed unclaimed is gone (410).
+const goneResponse = () => NextResponse.json({ error: "This offer has closed." }, { status: 410 });
export const GET = withDonkeyAuth(async (request) => {
const token = request.nextUrl.searchParams.get("token");
const offerId = token ? verifyCreditOfferToken(token) : null;
if (!offerId) return notFoundResponse();
const offer = await prisma.creditOffer.findUnique({
- select: { amountMicros: true, claimedAt: true, expiresAfterDays: true, kind: true, userId: true },
+ select: { amountMicros: true, claimedAt: true, closesAt: true, expiresAfterDays: true, kind: true, userId: true },
where: { id: offerId },
});
if (!offer || offer.kind !== MANUAL_OFFER_KIND) return notFoundResponse();
if (offer.userId !== request.donkey.userId) return forbiddenResponse();
+ if (!offer.claimedAt && !creditOfferOpen(offer, new Date())) return goneResponse();
return NextResponse.json({
claimed: offer.claimedAt !== null,
+ closesAt: offer.closesAt?.toISOString() ?? null,
credits: formatUsdPlain(creditMicrosToString(offer.amountMicros)),
lifetime: describeCreditLifetime(offer.expiresAfterDays),
});
@@ -58,6 +64,7 @@ export const POST = withDonkeyAuth(async (request) => {
});
} catch (error) {
if (error instanceof CreditOfferNotYoursError) return forbiddenResponse();
+ if (error instanceof CreditOfferClosedError) return goneResponse();
throw error;
}
});
diff --git a/site/src/app/api/credits/offers/route.ts b/site/src/app/api/credits/offers/route.ts
index 18b7ac87..b19ac5fd 100644
--- a/site/src/app/api/credits/offers/route.ts
+++ b/site/src/app/api/credits/offers/route.ts
@@ -56,6 +56,7 @@ export const POST = withSuperUser(async (request) => {
return NextResponse.json({
amountDollars: parsed.data.amountDollars,
offer: {
+ closesAt: offer.closesAt?.toISOString() ?? null,
emailSentAt: offer.emailSentAt?.toISOString() ?? null,
expiresAfterDays: offer.expiresAfterDays,
id: offer.id,
diff --git a/site/src/app/su/credits/page.tsx b/site/src/app/su/credits/page.tsx
index 3ff62c88..dab13f0f 100644
--- a/site/src/app/su/credits/page.tsx
+++ b/site/src/app/su/credits/page.tsx
@@ -26,6 +26,7 @@ import {
creditGrantExpiryPresets,
creditTopUpDefaultDollars,
creditTopUpPresetsDollars,
+ formatCreditExpiry,
maxCreditGrantDollars,
maxCreditGrantExpiryDays,
} from "@/lib/credits/top-up";
@@ -103,6 +104,8 @@ export default function SuCreditsPage() {
onSuccess: (result) => {
setLastResult(
`Offered $${amountDollars} to ${result.targetUser.email}. The credit lands when they claim it from the email${
+ result.offer.closesAt ? ` by ${formatCreditExpiry(new Date(result.offer.closesAt))}` : ""
+ }${
result.offer.expiresAfterDays === null
? " and never expires."
: `, and ${describeExpiry(result.offer.expiresAfterDays)} from then.`
diff --git a/site/src/emails/credits-offered.tsx b/site/src/emails/credits-offered.tsx
index 9e214dbb..6dc31a9a 100644
--- a/site/src/emails/credits-offered.tsx
+++ b/site/src/emails/credits-offered.tsx
@@ -27,6 +27,8 @@ type CreditsOfferedEmailProps = {
// How long the credits live once claimed, already worded ("7 days"), or
// null when they never expire.
lifetime: string | null;
+ // The last day the link works, already worded ("September 10, 2026").
+ claimBy: string;
claimUrl: string;
unsubscribeUrl: string;
};
@@ -35,6 +37,7 @@ export default function CreditsOfferedEmail({
name,
credits,
lifetime,
+ claimBy,
claimUrl,
unsubscribeUrl,
}: CreditsOfferedEmailProps) {
@@ -58,6 +61,7 @@ export default function CreditsOfferedEmail({
Claim {credits} in credits
</Button>
<Text className="text-[15px] leading-relaxed">
+ The link works until {claimBy}.{" "}
{lifetime !== null
? `Once claimed, they are good for ${lifetime}. `
: ""}
@@ -92,6 +96,7 @@ CreditsOfferedEmail.PreviewProps = {
name: "Ada",
credits: "$25.00",
lifetime: "7 days",
+ claimBy: "September 10, 2026",
claimUrl: "https://donkeycut.com/app?claim=preview",
unsubscribeUrl: "https://donkeycut.com/unsubscribe?token=preview",
} satisfies CreditsOfferedEmailProps;
diff --git a/site/src/lib/config/registry.ts b/site/src/lib/config/registry.ts
index e9085d3e..2f3ddfc5 100644
--- a/site/src/lib/config/registry.ts
+++ b/site/src/lib/config/registry.ts
@@ -79,6 +79,18 @@ export const SETTINGS = defineSettings({
title: "Credit expiry notice",
description: "How many days before signup or manually granted credits expire the account is emailed.",
},
+ manualCreditOffer: {
+ schema: z
+ .object({
+ // Days the emailed claim link stays open after it is sent.
+ claimWindowDays: z.number().int().min(1).max(365),
+ })
+ .strict(),
+ default: { claimWindowDays: 3 },
+ public: false,
+ title: "Manual credit offer",
+ description: "How many days the claim link in a credit offer email stays open.",
+ },
subscribeBonus: {
schema: z
.object({
@@ -121,7 +133,7 @@ export const SETTINGS = defineSettings({
// 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", "proAllowancePromotion"] as const satisfies readonly SettingKey[];
+export const PRODUCT_SETTING_KEYS = ["signupCredits", "creditExpiryNotice", "manualCreditOffer", "subscribeBonus", "proAllowancePromotion"] as const satisfies readonly SettingKey[];
export type SettingKey = keyof typeof SETTINGS;
export type Settings = SettingsOf<typeof SETTINGS>;
diff --git a/site/src/lib/credits/offers.test.ts b/site/src/lib/credits/offers.test.ts
new file mode 100644
index 00000000..b2d26ca2
--- /dev/null
+++ b/site/src/lib/credits/offers.test.ts
@@ -0,0 +1,13 @@
+import { describe, expect, test } from "bun:test";
+
+import { creditOfferOpen, manualOfferClosesAt } from "./offers";
+
+describe("a manual credit offer", () => {
+ test("closes the claim window a set number of days after the send", () => {
+ const sent = new Date("2026-09-07T10:00:00Z");
+ const closesAt = manualOfferClosesAt(3, sent);
+ expect(closesAt.toISOString()).toBe("2026-09-10T10:00:00.000Z");
+ expect(creditOfferOpen({ claimedAt: null, closesAt }, new Date("2026-09-10T09:59:59Z"))).toBe(true);
+ expect(creditOfferOpen({ claimedAt: null, closesAt }, new Date("2026-09-10T10:00:01Z"))).toBe(false);
+ });
+});
diff --git a/site/src/lib/credits/offers.ts b/site/src/lib/credits/offers.ts
index ce94220f..d9a8d0b5 100644
--- a/site/src/lib/credits/offers.ts
+++ b/site/src/lib/credits/offers.ts
@@ -2,6 +2,7 @@ import { createHmac, timingSafeEqual } from "node:crypto";
import type { CreditOffer } from "@/generated/prisma/client";
import { CUT_APP_BASE } from "@/cut/lib/appBase";
+import { getGlobalSetting } from "@/lib/config/effective";
import { DONKEYCUT_CANONICAL } from "@/cut/lib/hosts";
import { grantCredits } from "@/lib/credits/inference";
import { creditGrantExpiry } from "@/lib/credits/top-up";
@@ -43,11 +44,16 @@ export function creditOfferClaimUrl(offerId: string): string {
return `${DONKEYCUT_CANONICAL}${CUT_APP_BASE}?claim=${encodeURIComponent(creditOfferToken(offerId))}`;
}
+/** The last moment a claim link sent now can be used. */
+export function manualOfferClosesAt(claimWindowDays: number, now = new Date()): Date {
+ return new Date(now.getTime() + claimWindowDays * 24 * 60 * 60 * 1000);
+}
+
// Records the offer and emails the claim link. The row comes first so the
// link can name it, and stays if the send fails: the next attempt with the
// same recipient, amount and lifetime picks the unsent offer up again, and
// the send keys on the offer id, so the person gets one link however many
-// times the operator retries.
+// times the operator retries. The claim window runs from the send.
export async function createCreditOffer(input: {
amountMicros: bigint;
description?: string;
@@ -55,6 +61,8 @@ export async function createCreditOffer(input: {
offeredByUserId: string;
user: { email: string; id: string; name: string };
}) {
+ const { claimWindowDays } = await getGlobalSetting("manualCreditOffer");
+ const closesAt = manualOfferClosesAt(claimWindowDays);
const offer =
(await prisma.creditOffer.findFirst({
where: {
@@ -69,6 +77,7 @@ export async function createCreditOffer(input: {
(await prisma.creditOffer.create({
data: {
amountMicros: input.amountMicros,
+ closesAt,
description: input.description,
expiresAfterDays: input.expiresAfterDays,
kind: MANUAL_OFFER_KIND,
@@ -79,17 +88,21 @@ export async function createCreditOffer(input: {
await sendCreditsOfferedEmail(input.user, {
amountMicros: offer.amountMicros,
claimUrl: creditOfferClaimUrl(offer.id),
+ closesAt,
expiresAfterDays: offer.expiresAfterDays,
id: offer.id,
});
return prisma.creditOffer.update({
- data: { emailSentAt: new Date() },
+ data: { closesAt, emailSentAt: new Date() },
where: { id: offer.id },
});
}
export class CreditOfferNotYoursError extends Error {}
+// The claim window closed before the link was used.
+export class CreditOfferClosedError extends Error {}
+
/** Whether an offer can still be claimed now. */
export function creditOfferOpen(offer: { claimedAt: Date | null; closesAt: Date | null }, now: Date): boolean {
return offer.claimedAt === null && (offer.closesAt === null || now.getTime() <= offer.closesAt.getTime());
@@ -128,6 +141,7 @@ export async function claimCreditOffer(offerId: string, userId: string) {
const offer = await prisma.creditOffer.findUnique({ where: { id: offerId } });
if (!offer || offer.kind !== MANUAL_OFFER_KIND) return null;
if (offer.userId !== userId) throw new CreditOfferNotYoursError();
+ if (!offer.claimedAt && !creditOfferOpen(offer, new Date())) throw new CreditOfferClosedError();
return landCreditOffer(offer, {
description: "Manual credit grant",
source: "manual_dollar",
diff --git a/site/src/lib/email/send-credits-offered.ts b/site/src/lib/email/send-credits-offered.ts
index f32ae2d5..5ef50379 100644
--- a/site/src/lib/email/send-credits-offered.ts
+++ b/site/src/lib/email/send-credits-offered.ts
@@ -5,6 +5,7 @@ import {
import CreditsOfferedEmail from "@/emails/credits-offered";
import { creditMicrosToString } from "@/lib/credits/amounts";
import { formatUsdPlain } from "@/lib/credits/format-usd";
+import { formatCreditExpiry } from "@/lib/credits/top-up";
import {
bulkFrom,
emailFrom,
@@ -32,7 +33,7 @@ export function describeCreditLifetime(days: number | null): string | null {
// the footer still offers the opt-out.
export async function sendCreditsOfferedEmail(
user: EmailUser,
- offer: { amountMicros: bigint; claimUrl: string; expiresAfterDays: number | null; id: string },
+ offer: { amountMicros: bigint; claimUrl: string; closesAt: Date; expiresAfterDays: number | null; id: string },
): Promise<void> {
if (!isResendConfigured()) throw new ResendNotConfiguredError();
const from = bulkFrom();
@@ -47,6 +48,7 @@ export async function sendCreditsOfferedEmail(
replyTo: emailFrom() || from,
subject: `${credits} in AI credits is waiting for you`,
react: CreditsOfferedEmail({
+ claimBy: formatCreditExpiry(offer.closesAt),
claimUrl: offer.claimUrl,
credits,
lifetime: describeCreditLifetime(offer.expiresAfterDays),
diff --git a/site/src/queries/credits.ts b/site/src/queries/credits.ts
index d337f314..416397c4 100644
--- a/site/src/queries/credits.ts
+++ b/site/src/queries/credits.ts
@@ -125,7 +125,7 @@ export function useOfferCredits() {
userId?: string;
}) =>
apiFetch<{
- offer: { expiresAfterDays: number | null; id: string };
+ offer: { closesAt: string | null; expiresAfterDays: number | null; id: string };
targetUser: { email: string };
}>(
"/api/credits/offers",
@@ -138,6 +138,8 @@ export const creditOfferQueryKey = (token: string) => ["credits", "offer", token
export type CreditOffer = {
claimed: boolean;
+ // The last moment the offer can be claimed; null keeps it open.
+ closesAt: string | null;
// Formatted USD, "$5".
credits: string;
// "a week", or null when the credit keeps forever.
@@ -145,7 +147,7 @@ export type CreditOffer = {
};
// The offer a claim link names. 404 is a link that no longer opens anything;
-// 403 is an offer made to another account.
+// 403 is an offer made to another account; 410 is a claim window that closed.
export function useCreditOffer(token: string, options: { enabled?: boolean } = {}) {
return useQuery({
enabled: options.enabled ?? true,