Gift packages: buy a main package for someone, with a printable gift card
- /ajandek: the package, whom it is for and from whom, the recipient's address typed twice (or "I hand it over"), a message; paid on Stripe like any package, the invoice is the buyer's - On payment the gift gets its own code (not a promo code: it cannot be withdrawn, and it adds the whole package); redeemed on /bevaltas - The recipient's e-mail carries the message and the code, with the gift card attached as a PDF; the buyer's confirmation says it was a gift - /ajandekaim: codes, state, the card to download, sending it by e-mail (again, or to another address) up to three times - crates/gift-card draws the A4 card (example chart, questions avatar, QR code) as SVG and makes a PDF with krilla, fonts compiled in; the backend draws downloads on a blocking thread, the worker the e-mails - Telegram notices say "(ajándék)"; unpaid gifts go after a week Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useId, useState } from "react";
|
||||
|
||||
import { huf } from "@/components/PackageCards";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { contents } from "@/lib/packageContents";
|
||||
import type { Package, PayMethod } from "@/lib/types";
|
||||
|
||||
const MAX_MESSAGE = 300;
|
||||
const MAX_NAME = 60;
|
||||
|
||||
const looksLikeEmail = (s: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s.trim());
|
||||
const same = (a: string, b: string) => a.trim().toLowerCase() === b.trim().toLowerCase();
|
||||
|
||||
/**
|
||||
* The gift order: which package, whom it is for and from whom, how it gets
|
||||
* to the recipient (we e-mail it, the address typed twice; or the buyer
|
||||
* hands it over), and a message. Then Stripe's payment page, back to "My
|
||||
* gifts".
|
||||
*/
|
||||
export function GiftForm({
|
||||
packages,
|
||||
initial,
|
||||
defaultFrom,
|
||||
canPay,
|
||||
termsConsent,
|
||||
}: {
|
||||
packages: Package[];
|
||||
initial?: string;
|
||||
defaultFrom: string;
|
||||
canPay: PayMethod | null;
|
||||
termsConsent: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const id = useId();
|
||||
const start = packages.find((p) => p.id === initial) ?? packages.find((p) => p.id === "couple") ?? packages[0];
|
||||
const [pkg, setPkg] = useState(start?.id ?? "");
|
||||
const [name, setName] = useState("");
|
||||
const [byEmail, setByEmail] = useState(true);
|
||||
const [email, setEmail] = useState("");
|
||||
const [confirm, setConfirm] = useState("");
|
||||
const [from, setFrom] = useState(defaultFrom.slice(0, MAX_NAME));
|
||||
const [message, setMessage] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
// Back from Stripe's page (the browser may restore this page as it was).
|
||||
useEffect(() => {
|
||||
const reset = (e: PageTransitionEvent) => {
|
||||
if (e.persisted) setBusy(false);
|
||||
};
|
||||
window.addEventListener("pageshow", reset);
|
||||
return () => window.removeEventListener("pageshow", reset);
|
||||
}, []);
|
||||
|
||||
const chosen = packages.find((p) => p.id === pkg);
|
||||
const mismatch = byEmail && confirm.trim() !== "" && !same(email, confirm);
|
||||
const emailOk = !byEmail || (looksLikeEmail(email) && same(email, confirm));
|
||||
const stripe = canPay === "stripe" || canPay === "stripe_test";
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!chosen || !emailOk || !name.trim()) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const r = await api<{ id: string; url: string | null }>("/gifts/checkout", {
|
||||
body: {
|
||||
package: chosen.id,
|
||||
recipient_name: name.trim(),
|
||||
recipient_email: byEmail ? email.trim() : null,
|
||||
recipient_email_confirm: byEmail ? confirm.trim() : null,
|
||||
from_name: from.trim() || null,
|
||||
message: message.trim() || null,
|
||||
},
|
||||
});
|
||||
if (r.url) {
|
||||
window.location.assign(r.url);
|
||||
return;
|
||||
}
|
||||
router.push("/ajandekaim");
|
||||
} catch (err) {
|
||||
setError(errorText(err));
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="card gift-form" onSubmit={submit}>
|
||||
<fieldset className="gift-set">
|
||||
<legend className="label">Melyik csomagot adod?</legend>
|
||||
<div className="gift-packages">
|
||||
{packages.map((p) => (
|
||||
<label key={p.id} className={p.id === pkg ? "gift-option is-chosen" : "gift-option"}>
|
||||
<input type="radio" name={`${id}-pkg`} value={p.id} checked={p.id === pkg} onChange={() => setPkg(p.id)} />
|
||||
<span className="gift-option-head">
|
||||
<strong>{p.name}</strong>
|
||||
<span className="num">{huf(p.price_huf)}</span>
|
||||
</span>
|
||||
<span className="hint">{contents(p).join(" · ")}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label htmlFor={`${id}-name`}>Kinek szól?</label>
|
||||
<input
|
||||
id={`${id}-name`}
|
||||
className="inp"
|
||||
value={name}
|
||||
maxLength={MAX_NAME}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="Például: Bea"
|
||||
aria-describedby={`${id}-name-hint`}
|
||||
required
|
||||
/>
|
||||
<span id={`${id}-name-hint`} className="hint">
|
||||
Az utalványon: „{name.trim() || "Bea"} részére”
|
||||
{byEmail ? `, a levélben: „Szia ${name.trim() || "Bea"}!”` : ""}.
|
||||
</span>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor={`${id}-from`}>Kitől? (a te neved)</label>
|
||||
<input
|
||||
id={`${id}-from`}
|
||||
className="inp"
|
||||
value={from}
|
||||
maxLength={MAX_NAME}
|
||||
onChange={(e) => setFrom(e.target.value)}
|
||||
placeholder="Például: Anna"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset className="gift-set">
|
||||
<legend className="label">Hogyan kapja meg?</legend>
|
||||
<div className="gift-ways">
|
||||
<label className={byEmail ? "gift-option is-chosen" : "gift-option"}>
|
||||
<input type="radio" name={`${id}-way`} checked={byEmail} onChange={() => setByEmail(true)} />
|
||||
<strong>E-mailben küldjük el neki</strong>
|
||||
<span className="hint">Fizetés után azonnal megkapja a kódot, mellé az utalványt PDF-ben.</span>
|
||||
</label>
|
||||
<label className={!byEmail ? "gift-option is-chosen" : "gift-option"}>
|
||||
<input type="radio" name={`${id}-way`} checked={!byEmail} onChange={() => setByEmail(false)} />
|
||||
<strong>Én adom át</strong>
|
||||
<span className="hint">
|
||||
Letöltöd az utalványt PDF-ben: kinyomtathatod, vagy elküldheted te magad. Később innen is kérheted, hogy
|
||||
e-mailben küldjük el.
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
{byEmail && (
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label htmlFor={`${id}-email`}>A címzett e-mail-címe</label>
|
||||
<input
|
||||
id={`${id}-email`}
|
||||
className="inp"
|
||||
type="email"
|
||||
autoComplete="off"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor={`${id}-confirm`}>Még egyszer, ellenőrzésképp</label>
|
||||
<input
|
||||
id={`${id}-confirm`}
|
||||
className="inp"
|
||||
type="email"
|
||||
autoComplete="off"
|
||||
value={confirm}
|
||||
onChange={(e) => setConfirm(e.target.value)}
|
||||
aria-invalid={mismatch || undefined}
|
||||
aria-describedby={`${id}-confirm-msg`}
|
||||
required
|
||||
/>
|
||||
<span id={`${id}-confirm-msg`} className={mismatch ? "msg msg-error" : "hint"} aria-live="polite">
|
||||
{mismatch ? "A két cím nem egyezik." : "Hogy biztosan jó címre menjen."}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</fieldset>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor={`${id}-message`}>Személyes üzenet (nem kötelező)</label>
|
||||
<textarea
|
||||
id={`${id}-message`}
|
||||
className="inp"
|
||||
value={message}
|
||||
maxLength={MAX_MESSAGE}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
placeholder="Boldog születésnapot! Nézd meg, mit mesélnek rólad a csillagok."
|
||||
aria-describedby={`${id}-message-hint`}
|
||||
/>
|
||||
<span id={`${id}-message-hint`} className="hint">
|
||||
Rajta lesz az utalványon és a levélben. Link nem lehet benne. {message.length}/{MAX_MESSAGE}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="gift-submit">
|
||||
{chosen && (
|
||||
<p className="gift-total">
|
||||
<span className="muted">
|
||||
„{chosen.name}” csomag ajándékba{name.trim() ? `, ${name.trim()} részére` : ""}
|
||||
</span>
|
||||
<strong className="num">{huf(chosen.price_huf)}</strong>
|
||||
</p>
|
||||
)}
|
||||
{canPay ? (
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !chosen || !emailOk || !name.trim()}>
|
||||
{busy ? (stripe ? "Átirányítás…" : "Fizetés…") : stripe ? "Tovább a fizetéshez" : "Megveszem ajándékba"}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" className="btn" disabled>
|
||||
Hamarosan
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{canPay === "mock" && <p className="hint">Tesztüzem: a fizetés még nincs bekötve, a gomb nem terhel semmit.</p>}
|
||||
{stripe && (
|
||||
<p className="hint">
|
||||
<span aria-hidden="true">🔒</span> A fizetés a Stripe biztonságos oldalán történik. A számlát te kapod.
|
||||
{termsConsent && (
|
||||
<>
|
||||
{" "}
|
||||
Az ajándékkód a fizetés után azonnal elkészül, ezért a fizetésnél kéred a teljesítés megkezdését, és ezzel
|
||||
lemondasz a 14 napos elállási jogról. <Link href="/aszf">ÁSZF</Link>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{canPay === "stripe_test" && (
|
||||
<p className="hint">
|
||||
Stripe tesztmód (csak adminoknak látszik): kártyaszám 4242 4242 4242 4242, bármilyen jövőbeli lejárat és CVC.
|
||||
</p>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
|
||||
import { payMethod } from "@/lib/payments";
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
import type { Gift, Package, PublicConfig } from "@/lib/types";
|
||||
|
||||
import { GiftForm } from "./GiftForm";
|
||||
|
||||
export const metadata: Metadata = { title: "Ajándék csomag", robots: { index: false } };
|
||||
|
||||
type Props = { searchParams: Promise<{ csomag?: string }> };
|
||||
|
||||
/** Buying a package as a gift; `?csomag=` picks the package (links on the package cards). */
|
||||
export default async function GiftPage({ searchParams }: Props) {
|
||||
const { csomag } = await searchParams;
|
||||
const me = await requireMe(csomag ? `/ajandek?csomag=${encodeURIComponent(csomag)}` : "/ajandek");
|
||||
const [catalog, config, mine] = await Promise.all([
|
||||
backendGet<{ packages: Package[] }>("/v1/packages"),
|
||||
backendGet<PublicConfig>("/v1/config"),
|
||||
backendGet<{ gifts: Gift[] }>("/v1/gifts"),
|
||||
]);
|
||||
const packages = (catalog?.packages ?? []).filter((p) => p.tier === "main");
|
||||
const given = mine?.gifts.length ?? 0;
|
||||
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1080 }}>
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">Ajándék</span>
|
||||
<h1>Ajándékozz csomagot</h1>
|
||||
<p className="muted">
|
||||
Születési képlet, személyre szóló elemzések, kapcsolati összevetés: ajándékba annak, akit szeretsz. Ő egy
|
||||
ajándékkódot kap egy nyomtatható utalvánnyal, és a saját fiókjában váltja be.
|
||||
</p>
|
||||
{given > 0 && (
|
||||
<p className="hint">
|
||||
<Link href="/ajandekaim">Korábbi ajándékaim ({given}) →</Link>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="gift-layout">
|
||||
<GiftForm
|
||||
packages={packages}
|
||||
initial={csomag}
|
||||
defaultFrom={me.user.display_name ?? ""}
|
||||
canPay={payMethod(config, me)}
|
||||
termsConsent={config?.terms_consent === true}
|
||||
/>
|
||||
<aside className="gift-aside">
|
||||
<figure className="gift-sample">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src="/img/ajandek-utalvany.webp"
|
||||
width={420}
|
||||
height={594}
|
||||
alt="Minta ajándékutalvány: a csomag neve, a személyes üzenet, az ajándékkód és a QR-kód"
|
||||
/>
|
||||
<figcaption className="hint">Így néz ki az utalvány (A4-es PDF, nyomtatható)</figcaption>
|
||||
</figure>
|
||||
<section className="card gift-how" aria-labelledby="gift-how-title">
|
||||
<h2 id="gift-how-title">Hogyan működik?</h2>
|
||||
<ol>
|
||||
<li>Kiválasztod a csomagot, és megírod, kinek szól.</li>
|
||||
<li>Fizetés után elkészül az ajándékkód és az utalvány.</li>
|
||||
<li>E-mailben elküldjük neki, vagy letöltöd a PDF-et, és te adod át.</li>
|
||||
<li>Belép vagy regisztrál, beváltja a kódot, és a csomag az övé.</li>
|
||||
</ol>
|
||||
<p className="hint">A kód nem jár le, és egyszer váltható be. A számlát te kapod.</p>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
"use client";
|
||||
|
||||
import { useId, useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import type { Gift } from "@/lib/types";
|
||||
|
||||
const day = (iso: string) =>
|
||||
new Date(iso).toLocaleDateString("hu-HU", { timeZone: "Europe/Budapest", year: "numeric", month: "long", day: "numeric" });
|
||||
const time = (iso: string) => new Date(iso).toLocaleTimeString("hu-HU", { timeZone: "Europe/Budapest", hour: "2-digit", minute: "2-digit" });
|
||||
|
||||
/** The user's gifts: code, state, the card to download, and sending it by e-mail. */
|
||||
export function GiftList({ gifts: initial }: { gifts: Gift[] }) {
|
||||
const [gifts, setGifts] = useState(initial);
|
||||
return (
|
||||
<ul className="gift-list">
|
||||
{gifts.map((g) => (
|
||||
<GiftItem key={g.id} gift={g} onChange={(next) => setGifts((all) => all.map((x) => (x.id === next.id ? next : x)))} />
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
function GiftItem({ gift, onChange }: { gift: Gift; onChange: (g: Gift) => void }) {
|
||||
const id = useId();
|
||||
const [sending, setSending] = useState(false);
|
||||
const [email, setEmail] = useState("");
|
||||
const [confirm, setConfirm] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [sent, setSent] = useState<string | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const open = gift.status === "open";
|
||||
const mismatch = confirm.trim() !== "" && email.trim().toLowerCase() !== confirm.trim().toLowerCase();
|
||||
|
||||
async function send(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const next = await api<Gift>(`/gifts/${gift.id}/send`, {
|
||||
body: { recipient_email: email.trim(), recipient_email_confirm: confirm.trim() },
|
||||
});
|
||||
onChange(next);
|
||||
setSent(next.recipient_email);
|
||||
setSending(false);
|
||||
setEmail("");
|
||||
setConfirm("");
|
||||
} catch (err) {
|
||||
setError(errorText(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function copy() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(gift.code);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
} catch {
|
||||
// The code stays visible and selectable.
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<li className="card gift-item">
|
||||
<div className="gift-item-head">
|
||||
<div>
|
||||
<h2 className="gift-item-title">
|
||||
„{gift.package.name ?? gift.package.id}” csomag
|
||||
{gift.recipient_name && <span className="gift-item-for"> {gift.recipient_name} részére</span>}
|
||||
</h2>
|
||||
<span className="hint">Vásárolva: {day(gift.paid_at)}</span>
|
||||
</div>
|
||||
{gift.status === "redeemed" ? (
|
||||
<span className="badge">Beváltva{gift.redeemed_at ? `: ${day(gift.redeemed_at)}` : ""}</span>
|
||||
) : (
|
||||
<span className="badge badge-gold">Még nincs beváltva</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="gift-code-row">
|
||||
<span className="eyebrow">Ajándékkód</span>
|
||||
<code className="gift-code">{gift.code}</code>
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={copy}>
|
||||
{copied ? "Másolva" : "Másolás"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p className="gift-to">
|
||||
{gift.recipient_email ? (
|
||||
<>
|
||||
E-mailben elküldve ide: <strong>{gift.recipient_email}</strong>
|
||||
{gift.sendings > 1 ? ` (${gift.sendings}×)` : ""}
|
||||
</>
|
||||
) : (
|
||||
"Te adod át: töltsd le az utalványt."
|
||||
)}
|
||||
{gift.from_name && <span className="hint"> · Kitől: {gift.from_name}</span>}
|
||||
</p>
|
||||
{gift.message && <blockquote className="gift-message">{gift.message}</blockquote>}
|
||||
|
||||
<div className="form-actions">
|
||||
<a className="btn btn-primary btn-sm" href={`/api/v1/gifts/${gift.id}/card.pdf`} download>
|
||||
Utalvány letöltése (PDF)
|
||||
</a>
|
||||
{open && gift.can_send && !sending && (
|
||||
<button type="button" className="btn btn-sm" onClick={() => setSending(true)}>
|
||||
{gift.recipient_email ? "Újraküldés e-mailben" : "Küldés e-mailben"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{open && !gift.can_send && gift.sendings > 0 && (
|
||||
<p className="hint">E-mailben már többször elküldtük. Ha nem érkezett meg, töltsd le az utalványt, és küldd el te.</p>
|
||||
)}
|
||||
{sent && (
|
||||
<p className="msg msg-ok" role="status">
|
||||
Elküldtük ide: {sent}.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{sending && (
|
||||
<form className="gift-send" onSubmit={send}>
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label htmlFor={`${id}-email`}>Kinek küldjük?</label>
|
||||
<input
|
||||
id={`${id}-email`}
|
||||
className="inp"
|
||||
type="email"
|
||||
autoComplete="off"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder={gift.recipient_email ?? ""}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor={`${id}-confirm`}>Még egyszer, ellenőrzésképp</label>
|
||||
<input
|
||||
id={`${id}-confirm`}
|
||||
className="inp"
|
||||
type="email"
|
||||
autoComplete="off"
|
||||
value={confirm}
|
||||
onChange={(e) => setConfirm(e.target.value)}
|
||||
aria-invalid={mismatch || undefined}
|
||||
required
|
||||
/>
|
||||
{mismatch && <span className="msg msg-error">A két cím nem egyezik.</span>}
|
||||
</div>
|
||||
</div>
|
||||
{gift.send_again_at && (
|
||||
<p className="hint">Most küldtük el: {time(gift.send_again_at)} után küldheted újra.</p>
|
||||
)}
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn btn-primary btn-sm" disabled={busy || mismatch || !email.trim()}>
|
||||
{busy ? "Küldés…" : "Elküldöm"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setSending(false)}>
|
||||
Mégse
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
import type { Gift } from "@/lib/types";
|
||||
|
||||
import { GiftList } from "./GiftList";
|
||||
|
||||
export const metadata: Metadata = { title: "Ajándékaim", robots: { index: false } };
|
||||
|
||||
/** The packages the user bought as gifts: codes, cards to download, sending them by e-mail. */
|
||||
export default async function MyGiftsPage() {
|
||||
await requireMe("/ajandekaim");
|
||||
const gifts = (await backendGet<{ gifts: Gift[] }>("/v1/gifts"))?.gifts ?? [];
|
||||
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 900 }}>
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">Ajándék</span>
|
||||
<h1>Ajándékaim</h1>
|
||||
<p className="muted">
|
||||
Az ajándékba vett csomagjaid. Ha nem e-mailben adnád át, töltsd le az utalványt PDF-ben: kinyomtathatod, vagy
|
||||
elküldheted te magad. Amíg nem váltották be, e-mailben is elküldhetjük, akár másik címre.
|
||||
</p>
|
||||
<div className="form-actions">
|
||||
<Link className="btn btn-primary" href="/ajandek">
|
||||
Új ajándék
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{gifts.length === 0 ? (
|
||||
<section className="card">
|
||||
<p className="muted">
|
||||
Még nem vettél ajándékot. Egy csomagot bárkinek megvehetsz: e-mailben kapja meg, vagy te adod át egy
|
||||
nyomtatható utalvánnyal. <Link href="/ajandek">Ajándékozás →</Link>
|
||||
</p>
|
||||
</section>
|
||||
) : (
|
||||
// A new gift (back from paying) or a change starts the list afresh.
|
||||
<GiftList key={gifts.map((g) => `${g.id}:${g.status}:${g.sendings}`).join()} gifts={gifts} />
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -3,22 +3,26 @@ import type { Metadata } from "next";
|
||||
import { RedeemCode } from "@/components/RedeemCode";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
export const metadata: Metadata = { title: "Promókód beváltása", robots: { index: false } };
|
||||
export const metadata: Metadata = { title: "Kód beváltása", robots: { index: false } };
|
||||
|
||||
type Props = { searchParams: Promise<{ kod?: string }> };
|
||||
|
||||
/** Redeeming a promo code; `?kod=` fills it in (links in invitations). */
|
||||
/** Redeeming a promo or gift code; `?kod=` fills it in (links in invitations and gift e-mails). */
|
||||
export default async function RedeemPage({ searchParams }: Props) {
|
||||
const { kod } = await searchParams;
|
||||
await requireMe(kod ? `/bevaltas?kod=${encodeURIComponent(kod)}` : "/bevaltas");
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 640 }}>
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">Promókód</span>
|
||||
<h1>Promókód beváltása</h1>
|
||||
<span className="eyebrow">Promókód, ajándékkód</span>
|
||||
<h1>Kód beváltása</h1>
|
||||
<p className="muted">
|
||||
Í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.
|
||||
Írd be a kapott kódot. Egy kód egyszer váltható be. Az ajándékba kapott csomag teljes egészében hozzáadódik
|
||||
az egyenlegedhez.
|
||||
</p>
|
||||
<p className="hint">
|
||||
Promókódnál az egyenlegedet a csomag szintjéig töltjük fel: amit már elhasználtál belőle, visszakapod, ami
|
||||
ennél több van, megmarad.
|
||||
</p>
|
||||
</div>
|
||||
<section className="card">
|
||||
|
||||
@@ -96,7 +96,20 @@ export default async function PackagesPage() {
|
||||
</p>
|
||||
)}
|
||||
|
||||
<PackageCards packages={packages} canPay={canPay} />
|
||||
<PackageCards packages={packages} canPay={canPay} giftLinks />
|
||||
|
||||
<section className="card gift-banner" aria-labelledby="gift-title">
|
||||
<div>
|
||||
<h2 id="gift-title">Ajándékba is adhatod</h2>
|
||||
<p className="muted">
|
||||
A három fő csomag bármelyikét megveheted másnak: e-mailben elküldjük neki egy nyomtatható utalvánnyal, vagy
|
||||
letöltöd, és te adod át. A kódot ő váltja be a saját fiókjában, és nem jár le.
|
||||
</p>
|
||||
</div>
|
||||
<Link className="btn" href="/ajandek">
|
||||
Megajándékozok valakit
|
||||
</Link>
|
||||
</section>
|
||||
|
||||
<section className="field" aria-labelledby="addon-title" style={{ gap: 12 }}>
|
||||
<h2 id="addon-title">Kiegészítők</h2>
|
||||
|
||||
@@ -1511,3 +1511,73 @@ span.tarot-fan-card { cursor: default; }
|
||||
.sky-events li { grid-template-columns: 24px minmax(0, 1fr); }
|
||||
.sky-events li .num { grid-column: 2; }
|
||||
}
|
||||
|
||||
/* Gifts: the order form, "My gifts", the link on the package cards */
|
||||
.pkg-gift {
|
||||
align-self: center; display: inline-flex; align-items: center; min-height: 36px;
|
||||
font-size: 14px; color: var(--gold); text-decoration: none;
|
||||
}
|
||||
.pkg-gift:hover { color: var(--gold-hover); text-decoration: underline; }
|
||||
.gift-banner { flex-direction: row; align-items: center; justify-content: space-between; gap: 20px; border-color: rgba(217, 180, 106, 0.35); }
|
||||
.gift-banner h2 { font-size: 24px; }
|
||||
.gift-banner p { margin: 6px 0 0; }
|
||||
.gift-banner .btn { flex: none; }
|
||||
.gift-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
|
||||
.gift-aside { display: flex; flex-direction: column; gap: 16px; }
|
||||
.gift-sample { margin: 0; display: flex; flex-direction: column; gap: 8px; align-items: center; }
|
||||
.gift-sample img {
|
||||
width: 100%; max-width: 320px; height: auto; border-radius: 6px;
|
||||
box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(217, 180, 106, 0.25);
|
||||
}
|
||||
.gift-how { gap: 10px; }
|
||||
.gift-how h2 { font-size: 22px; }
|
||||
.gift-how ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); font-size: 14px; }
|
||||
.gift-how p { margin: 0; }
|
||||
.gift-form { gap: 22px; }
|
||||
.gift-set { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
||||
.gift-set legend { padding: 0; margin-bottom: 10px; }
|
||||
.gift-packages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
|
||||
.gift-ways { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
|
||||
.gift-option {
|
||||
position: relative; display: flex; flex-direction: column; gap: 6px; padding: 14px 14px 14px 44px; cursor: pointer;
|
||||
border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel-2);
|
||||
}
|
||||
.gift-option:hover { border-color: #5a6790; }
|
||||
.gift-option.is-chosen { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
|
||||
.gift-option input { position: absolute; left: 14px; top: 16px; width: 18px; height: 18px; margin: 0; accent-color: var(--gold); }
|
||||
.gift-option:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.gift-option-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
|
||||
.gift-option-head strong { font-family: var(--font-display); font-size: 21px; font-weight: 600; }
|
||||
.gift-packages .gift-option-head { flex-direction: column; align-items: flex-start; gap: 2px; }
|
||||
.gift-packages .gift-option-head .num { color: var(--gold); }
|
||||
.gift-submit { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--line); }
|
||||
.gift-total { margin: 0; display: flex; flex-direction: column; gap: 2px; }
|
||||
.gift-total strong { font-family: var(--font-display); font-size: 28px; font-weight: 600; }
|
||||
.gift-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
|
||||
.gift-item { gap: 14px; }
|
||||
.gift-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
|
||||
.gift-item-title { font-size: 24px; }
|
||||
.gift-item-for { font-style: italic; font-weight: 500; color: var(--gold); }
|
||||
.gift-code-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
||||
.gift-code { font: 600 20px var(--font-body); letter-spacing: 1.5px; color: var(--ink); user-select: all; }
|
||||
.gift-to { margin: 0; color: var(--ink-2); }
|
||||
.gift-message {
|
||||
margin: 0; padding: 4px 0 4px 14px; border-left: 2px solid rgba(217, 180, 106, 0.5);
|
||||
font-family: var(--font-display); font-style: italic; font-size: 18px; color: var(--ink-2); white-space: pre-line;
|
||||
}
|
||||
.gift-send { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
|
||||
@media (max-width: 900px) {
|
||||
.gift-layout { grid-template-columns: 1fr; }
|
||||
.gift-aside { flex-direction: row; align-items: flex-start; }
|
||||
.gift-sample { flex: 0 0 180px; }
|
||||
.gift-how { flex: 1; }
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.gift-banner { flex-direction: column; align-items: stretch; }
|
||||
.gift-packages, .gift-ways { grid-template-columns: 1fr; }
|
||||
.gift-packages .gift-option-head { flex-direction: row; align-items: baseline; justify-content: space-between; }
|
||||
.gift-aside { flex-direction: column; }
|
||||
.gift-sample { flex: none; }
|
||||
.gift-sample img { max-width: 240px; }
|
||||
.gift-submit .btn { width: 100%; }
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ export function PackageCards({
|
||||
canPay,
|
||||
compact = false,
|
||||
row = false,
|
||||
giftLinks = false,
|
||||
onBought,
|
||||
}: {
|
||||
packages: Package[];
|
||||
@@ -32,6 +33,8 @@ export function PackageCards({
|
||||
compact?: boolean;
|
||||
/** One line per package (name, price, button), for tight places like the question panel. */
|
||||
row?: boolean;
|
||||
/** A "give it as a gift" link under the buy button of the main packages. */
|
||||
giftLinks?: boolean;
|
||||
/** After a stand-in purchase (default: reload the page data). */
|
||||
onBought?: (p: Package) => Promise<void> | void;
|
||||
}) {
|
||||
@@ -153,6 +156,11 @@ export function PackageCards({
|
||||
</p>
|
||||
)}
|
||||
{buyButton(p)}
|
||||
{giftLinks && canPay && p.tier === "main" && (
|
||||
<Link href={`/ajandek?csomag=${p.id}`} className="pkg-gift">
|
||||
Ajándékba adom →
|
||||
</Link>
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -41,12 +41,19 @@ export function PaymentReturn() {
|
||||
(async () => {
|
||||
for (let i = 0; i < POLLS && !stopped; i++) {
|
||||
try {
|
||||
const r = await api<{ status: string; name: string | null }>(
|
||||
`/payments/checkout/${encodeURIComponent(value)}`,
|
||||
);
|
||||
const r = await api<{
|
||||
status: string;
|
||||
name: string | null;
|
||||
gift: { id: string; recipient_name: string | null; recipient_email: string | null } | null;
|
||||
}>(`/payments/checkout/${encodeURIComponent(value)}`);
|
||||
if (stopped) return;
|
||||
if (r.status === "paid") {
|
||||
setNotice({ kind: "ok", text: `Köszönjük! Jóváírtuk: ${r.name ?? "a csomagod"}.` });
|
||||
const text = !r.gift
|
||||
? `Köszönjük! Jóváírtuk: ${r.name ?? "a csomagod"}.`
|
||||
: r.gift.recipient_email
|
||||
? `Köszönjük! Az ajándékot elküldtük ide: ${r.gift.recipient_email}. Az utalványt lent le is töltheted.`
|
||||
: "Köszönjük! Az ajándékutalvány elkészült: lent letöltheted, és átadhatod.";
|
||||
setNotice({ kind: "ok", text });
|
||||
clean();
|
||||
router.refresh();
|
||||
return;
|
||||
|
||||
@@ -18,18 +18,23 @@ const UNITS: Record<string, string> = {
|
||||
forecast: "éves előrejelzés",
|
||||
person: "személyhely",
|
||||
question: "kérdés",
|
||||
tarot: "kártyajóslás",
|
||||
};
|
||||
|
||||
/** "+2 képletelemzés, +3 kérdés" */
|
||||
/** "+2 képletelemzés, +3 kérdés", in the order of UNITS. */
|
||||
function addedText(added: Record<string, number>): string {
|
||||
const order = Object.keys(UNITS);
|
||||
const rank = (unit: string) => (order.includes(unit) ? order.indexOf(unit) : order.length);
|
||||
return Object.entries(added)
|
||||
.sort(([a], [b]) => rank(a) - rank(b))
|
||||
.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).
|
||||
* (used ones come back, more than that stays); a gift code adds the whole
|
||||
* package.
|
||||
*/
|
||||
export function RedeemCode({ initial = "", compact = false }: { initial?: string; compact?: boolean }) {
|
||||
const router = useRouter();
|
||||
@@ -37,17 +42,21 @@ export function RedeemCode({ initial = "", compact = false }: { initial?: string
|
||||
const [code, setCode] = useState(format(initial));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [got, setGot] = useState<{ name: string; added: string } | null>(null);
|
||||
const [got, setGot] = useState<{ name: string; added: string; gift: { from_name: string | null } | null } | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
async function redeem(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
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 ?? {}) });
|
||||
const r = await api<{
|
||||
package: { name: string };
|
||||
added: Record<string, number>;
|
||||
gift?: { from_name: string | null };
|
||||
}>("/promo-codes/redeem", { body: { code } });
|
||||
setGot({ name: r.package.name, added: addedText(r.added ?? {}), gift: r.gift ?? null });
|
||||
setCode("");
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
@@ -85,12 +94,19 @@ export function RedeemCode({ initial = "", compact = false }: { initial?: string
|
||||
</div>
|
||||
<div id={`${id}-msg`} aria-live="polite">
|
||||
{error && <p className="msg msg-error">{error}</p>}
|
||||
{got && (
|
||||
<p className="msg msg-ok">
|
||||
Beváltva: <strong>{got.name}</strong>. Feltöltöttük az egyenlegedet: {got.added}.{" "}
|
||||
<Link href="/keplet">Tovább a képletedhez</Link>
|
||||
</p>
|
||||
)}
|
||||
{got &&
|
||||
(got.gift ? (
|
||||
<p className="msg msg-ok">
|
||||
Beváltva: <strong>{got.name}</strong>
|
||||
{got.gift.from_name ? `, ${got.gift.from_name} ajándéka` : " ajándék"}. Hozzáadtuk az egyenlegedhez:{" "}
|
||||
{got.added}. <Link href="/keplet">Tovább a képletedhez</Link>
|
||||
</p>
|
||||
) : (
|
||||
<p className="msg msg-ok">
|
||||
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>
|
||||
</form>
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { LogoutButton } from "./LogoutButton";
|
||||
|
||||
/**
|
||||
* The account menu under the user's name (top right): profile, invoices,
|
||||
* redeeming a code, logging out. Closes on a click outside, Escape, or
|
||||
* redeeming a code, giving a gift, logging out. Closes on a click outside, Escape, or
|
||||
* moving to another page.
|
||||
*/
|
||||
export function UserMenu({ name, invoices }: { name: string; invoices: boolean }) {
|
||||
@@ -39,6 +39,7 @@ export function UserMenu({ name, invoices }: { name: string; invoices: boolean }
|
||||
{ href: "/profil", label: "Profil" },
|
||||
...(invoices ? [{ href: "/szamlak", label: "Számláim" }] : []),
|
||||
{ href: "/bevaltas", label: "Kód beváltása" },
|
||||
{ href: "/ajandek", label: "Ajándékozás" },
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
@@ -633,6 +633,29 @@ export interface PromoCode {
|
||||
redeemed_by: { email: string; name: string | null } | null;
|
||||
}
|
||||
|
||||
/** A package the user bought as a gift (`GET /v1/gifts`). */
|
||||
export interface Gift {
|
||||
id: string;
|
||||
package: { id: string; name: string | null };
|
||||
/** Whom it is for (on the card: "Bea részére"). */
|
||||
recipient_name: string | null;
|
||||
/** Where it was e-mailed (null: the buyer hands it over). */
|
||||
recipient_email: string | null;
|
||||
from_name: string | null;
|
||||
message: string | null;
|
||||
paid_at: string;
|
||||
/** ABCD-EFGH-JKLM */
|
||||
code: string;
|
||||
status: "open" | "redeemed";
|
||||
redeemed_at: string | null;
|
||||
/** E-mails sent so far. */
|
||||
sendings: number;
|
||||
/** Whether it can be sent by e-mail (again). */
|
||||
can_send: boolean;
|
||||
/** Not before this (just sent). */
|
||||
send_again_at: string | null;
|
||||
}
|
||||
|
||||
/** A "how compatible are we?" invitation of the user (`GET /v1/invites`). */
|
||||
export interface PersonInvite {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user