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
@@ -2,6 +2,7 @@
import { useCallback, useEffect, useState } from "react";
import { usePackages } from "@/components/PackageCards";
import { api, errorText } from "@/lib/api";
import { formatDate } from "@/lib/astro";
import type { AdminInvitation, InvitationResult, WaitlistEntry } from "@/lib/types";
@@ -104,6 +105,8 @@ function InviteForm({ onSent }: { onSent: () => Promise<void> }) {
const [emails, setEmails] = useState("");
const [message, setMessage] = useState("");
const [locale, setLocale] = useState("hu");
const [pkg, setPkg] = useState("");
const packages = usePackages();
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [results, setResults] = useState<InvitationResult[] | null>(null);
@@ -116,7 +119,7 @@ function InviteForm({ onSent }: { onSent: () => Promise<void> }) {
setResults(null);
try {
const res = await api<{ results: InvitationResult[] }>("/admin/invitations", {
body: { emails: parseEmails(emails), message: message.trim() || null, locale },
body: { emails: parseEmails(emails), message: message.trim() || null, locale, package: pkg || null },
});
setResults(res.results);
if (res.results.some((r) => r.status === "invited")) setEmails("");
@@ -163,6 +166,17 @@ function InviteForm({ onSent }: { onSent: () => Promise<void> }) {
</span>
</div>
<div className="row" style={{ gap: 12, alignItems: "flex-end", flexWrap: "wrap" }}>
<div className="field" style={{ minWidth: 220 }}>
<label htmlFor="invite-package">Ajándék csomag</label>
<select id="invite-package" className="inp" value={pkg} onChange={(e) => setPkg(e.target.value)}>
<option value="">nincs</option>
{(packages ?? []).map((p) => (
<option key={p.id} value={p.id}>
{p.name}
</option>
))}
</select>
</div>
<div className="field" style={{ width: 160 }}>
<label htmlFor="invite-locale">A levél nyelve</label>
<select id="invite-locale" className="inp" value={locale} onChange={(e) => setLocale(e.target.value)}>
@@ -175,6 +189,12 @@ function InviteForm({ onSent }: { onSent: () => Promise<void> }) {
</button>
</div>
</form>
{pkg && (
<p className="hint" style={{ margin: 0 }}>
Minden meghívott kap egy promókódot erre a csomagra. A levélben benne lesz, és a regisztrációkor magától
beváltódik. A meghívó visszavonása a kódot is visszavonja.
</p>
)}
{error && (
<p className="msg msg-error" role="alert">
{error}
@@ -187,18 +207,19 @@ function InviteForm({ onSent }: { onSent: () => Promise<void> }) {
<span className={r.status === "invited" ? "msg-ok" : "muted"}>
{r.email}: {RESULT[r.status]}
</span>
{r.promo_code && <code className="promo-code">{r.promo_code}</code>}
{r.url && <CopyLink url={r.url} />}
</li>
))}
</ul>
)}
<MailPreview message={message} locale={locale} />
<MailPreview message={message} locale={locale} pkg={pkg} />
</section>
);
}
/** The invitation e-mail as the recipient sees it, and a test copy to the admin. */
function MailPreview({ message, locale }: { message: string; locale: string }) {
function MailPreview({ message, locale, pkg }: { message: string; locale: string; pkg: string }) {
const [mail, setMail] = useState<{ subject: string; html: string; text: string } | null>(null);
const [view, setView] = useState<"html" | "text">("html");
const [busy, setBusy] = useState(false);
@@ -210,7 +231,7 @@ function MailPreview({ message, locale }: { message: string; locale: string }) {
try {
const res = await api<{ subject: string; html: string; text: string; sent_to: string | null }>(
"/admin/invitations/preview",
{ body: { message: message.trim() || null, locale, send_to_me: sendToMe } },
{ body: { message: message.trim() || null, locale, send_to_me: sendToMe, package: pkg || null } },
);
setMail(res);
if (res.sent_to) setNote({ ok: true, text: `Tesztlevél a sorban: ${res.sent_to}. A linkjei nem működnek.` });
@@ -337,6 +358,12 @@ function InvitationRow({ invitation: i, onChange }: { invitation: AdminInvitatio
<td>
<span className={`badge invite-${i.status}`}>{STATUS[i.status]}</span>
{i.accepted_by && <div className="hint">{i.accepted_by}</div>}
{i.package && (
<div className="hint" title={i.package.code ?? undefined}>
Ajándék: {i.package.name ?? i.package.id}
{i.package.redeemed_at ? " (beváltva)" : ""}
</div>
)}
</td>
<td>
<span className={i.mail === "failed" ? "msg-error" : i.mail === "queued" ? "muted" : undefined}>
+2 -2
View File
@@ -17,8 +17,8 @@ export default async function RedeemPage({ searchParams }: Props) {
<span className="eyebrow">Promókód</span>
<h1>Promókód beváltása</h1>
<p className="muted">
Írd be a kapott kódot. A hozzá tartozó csomag azonnal a tiéd, az elemzései nem járnak le. Egy kód egyszer
váltható be.
Írd be a kapott kódot. Az egyenlegedet azonnal feltöltjük a csomag szintjéig: amit már elhasználtál belőle,
visszakapod, ami ennél több van, megmarad. Egy kód egyszer váltható be.
</p>
</div>
<section className="card">