Invitations with a package; promo codes fill up the balance
CI / test (push) Successful in 1m15s
CI / build (push) Successful in 5m15s
CI / deploy (push) Skipped

An admin can pick a package when inviting: each invitee gets a promo code
(in the e-mail and its preview, kept on resend), redeemed by itself at sign
up; revoking the invitation withdraws it, and the list shows the package.

Redeeming a promo code now fills the units up to the package's amounts:
used units come back, more than that stays. A code that would add nothing
stays open, with a message saying so; the answer tells what was added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-19 09:57:01 +00:00
co-authored by Claude Opus 5.5
parent 054fb930f5
commit 7b23d71526
13 changed files with 458 additions and 66 deletions
@@ -12,22 +12,42 @@ function format(input: string): string {
return clean.match(/.{1,4}/g)?.join("-") ?? "";
}
/** Redeeming a promo code: the package arrives at once. */
const UNITS: Record<string, string> = {
natal: "képletelemzés",
synastry: "kapcsolati elemzés",
forecast: "éves előrejelzés",
person: "személyhely",
question: "kérdés",
};
/** "+2 képletelemzés, +3 kérdés" */
function addedText(added: Record<string, number>): string {
return Object.entries(added)
.map(([unit, n]) => `+${n} ${UNITS[unit] ?? unit}`)
.join(", ");
}
/**
* Redeeming a promo code. It fills the units up to the package's amounts
* (used ones come back, more than that stays).
*/
export function RedeemCode({ initial = "", compact = false }: { initial?: string; compact?: boolean }) {
const router = useRouter();
const id = useId();
const [code, setCode] = useState(format(initial));
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [got, setGot] = useState<string | null>(null);
const [got, setGot] = useState<{ name: string; added: string } | null>(null);
async function redeem(e: React.FormEvent) {
e.preventDefault();
setBusy(true);
setError(null);
try {
const r = await api<{ package: { name: string } }>("/promo-codes/redeem", { body: { code } });
setGot(r.package.name);
const r = await api<{ package: { name: string }; added: Record<string, number> }>("/promo-codes/redeem", {
body: { code },
});
setGot({ name: r.package.name, added: addedText(r.added ?? {}) });
setCode("");
router.refresh();
} catch (err) {
@@ -67,8 +87,8 @@ export function RedeemCode({ initial = "", compact = false }: { initial?: string
{error && <p className="msg msg-error">{error}</p>}
{got && (
<p className="msg msg-ok">
Megkaptad: <strong>{got}</strong>. Az elemzéseid már felhasználhatók,{" "}
<Link href="/keplet">indulhat a képleted</Link>.
Beváltva: <strong>{got.name}</strong>. Feltöltöttük az egyenlegedet: {got.added}.{" "}
<Link href="/keplet">Tovább a képletedhez</Link>
</p>
)}
</div>