Promo codes; purchases off in production
CI / test (push) Successful in 1m11s
CI / build (push) Successful in 5m38s
CI / deploy (push) Skipped

Admins make promo codes for a package (Admin → Promókódok: batch, note, copy
all), list them filtered (unused by default, used, revoked; by package; by
code, note or redeemer) and withdraw unused ones. A logged-in user redeems a
code once (header link, /bevaltas?kod=... prefilled, packages page, and the
analysis and question offers point there) and gets the package as an order
with source 'promo'. Failed redemptions are rate limited.

Production purchases are off: MOCK_PAYMENTS now defaults to false in the
deploy compose, so package cards say 'Hamarosan'.

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:45:42 +00:00
co-authored by Claude Opus 5.5
parent 19df36369c
commit 054fb930f5
19 changed files with 863 additions and 5 deletions
@@ -3,6 +3,7 @@ import Link from "next/link";
const PAGES = [
{ href: "/admin", label: "Felhasználók" },
{ href: "/admin/meghivok", label: "Meghívók" },
{ href: "/admin/promokodok", label: "Promókódok" },
{ href: "/admin/promptok", label: "Promptok" },
{ href: "/admin/modellek", label: "Modellek" },
{ href: "/admin/hibak", label: "Hibanapló" },
@@ -1,5 +1,6 @@
"use client";
import Link from "next/link";
import { useCallback, useEffect, useState } from "react";
import { api, ApiError, errorText } from "@/lib/api";
@@ -218,7 +219,9 @@ export function AnalysisQuestions({
<PackageChooser ids={["addon_questions"]} canPay={canPay} onBought={bought} />
</div>
) : (
<p className="hint">Most nincs felhasználható kérdésed. Kérdéseket hamarosan vásárolhatsz.</p>
<p className="hint">
Most nincs felhasználható kérdésed. Ha kaptál promókódot, <Link href="/bevaltas">váltsd be</Link>.
</p>
)}
</section>
);
@@ -273,7 +273,10 @@ export function DetailedAnalysis({
Példa megtekintése
</Link>
)}
<span className="hint">A részletes elemzés fizetős; a csomagok hamarosan elérhetők.</span>
<Link href="/bevaltas" className="btn btn-primary">
Promókód beváltása
</Link>
<span className="hint">A részletes elemzéshez csomag kell. Ha kaptál promókódot, váltsd be.</span>
</div>
)}
</section>
@@ -0,0 +1,77 @@
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useId, useState } from "react";
import { api, ApiError, errorText } from "@/lib/api";
/** Typing help: upper case, groups of four (ABCD-EFGH-JKLM). */
function format(input: string): string {
const clean = input.toUpperCase().replace(/[^0-9A-Z]/g, "").slice(0, 32);
return clean.match(/.{1,4}/g)?.join("-") ?? "";
}
/** Redeeming a promo code: the package arrives at once. */
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);
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);
setCode("");
router.refresh();
} catch (err) {
setError(
err instanceof ApiError && err.status === 429
? "Túl sok sikertelen próbálkozás. Várj negyed órát, és próbáld újra."
: errorText(err),
);
} finally {
setBusy(false);
}
}
return (
<form className={compact ? "redeem redeem-compact" : "redeem"} onSubmit={redeem}>
<label htmlFor={id} className={compact ? "label" : "sr-only"}>
Promókód
</label>
<div className="redeem-row">
<input
id={id}
className="inp redeem-input"
value={code}
onChange={(e) => setCode(format(e.target.value))}
placeholder="XXXX-XXXX-XXXX"
autoComplete="off"
autoCapitalize="characters"
spellCheck={false}
inputMode="text"
aria-describedby={`${id}-msg`}
/>
<button type="submit" className="btn btn-primary" disabled={busy || code.replace(/-/g, "").length < 8}>
{busy ? "Beváltás…" : "Beváltom"}
</button>
</div>
<div id={`${id}-msg`} aria-live="polite">
{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>.
</p>
)}
</div>
</form>
);
}
@@ -58,6 +58,9 @@ export function SiteHeader({ me }: { me: Me }) {
<NavLinks links={links} />
<div className="who">
<PackageBadge me={me} />
<Link href="/bevaltas" className="redeem-link">
Kód beváltása
</Link>
<span className="who-name">{me.user.display_name || me.user.email}</span>
<LogoutButton />
</div>