Invitations with a package; promo codes fill up the balance
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:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user