Christmas gifts and timed gift e-mails

- Gifts bought 15 Nov - 6 Jan get a Christmas card ("Boldog karácsonyt és
  csillagos 2027-et!", snowflakes) and a Christmas e-mail subject.
- The buyer can time the gift e-mail (e.g. Christmas morning); "Küldés most"
  replaces a waiting one, a refund takes it back.
- Admin: timed e-mails by hour (waiting / sent / failed), e-mail state per gift.
- /karacsony landing page; seasonal hints on /csomagok and /ajandek.

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-24 13:46:35 +00:00
co-authored by Claude Opus 5.5
parent 227e8b5b80
commit 382bd31271
22 changed files with 1016 additions and 209 deletions
+112 -1
View File
@@ -7,6 +7,7 @@ import { useEffect, useId, useState } from "react";
import { huf } from "@/components/PackageCards";
import { api, errorText } from "@/lib/api";
import { contents } from "@/lib/packageContents";
import { christmasMorning } from "@/lib/season";
import type { Package, PayMethod } from "@/lib/types";
const MAX_MESSAGE = 300;
@@ -17,6 +18,19 @@ const looksLikeEmail = (s: string) =>
const same = (a: string, b: string) =>
a.trim().toLowerCase() === b.trim().toLowerCase();
/** `2026-12-24` on the browser's clock. */
const localDay = (d: Date) =>
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
/** "dec. 24. 8:00" */
const whenText = (d: Date) =>
d.toLocaleString("hu-HU", {
month: "short",
day: "numeric",
hour: "numeric",
minute: "2-digit",
});
/**
* 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
@@ -49,6 +63,10 @@ export function GiftForm({
const [confirm, setConfirm] = useState("");
const [from, setFrom] = useState(defaultFrom.slice(0, MAX_NAME));
const [message, setMessage] = useState("");
const [timed, setTimed] = useState(false);
const xmas = christmasMorning();
const [day, setDay] = useState(xmas ? localDay(xmas) : "");
const [clock, setClock] = useState("08:00");
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).
@@ -64,6 +82,14 @@ export function GiftForm({
const mismatch = byEmail && confirm.trim() !== "" && !same(email, confirm);
const emailOk = !byEmail || (looksLikeEmail(email) && same(email, confirm));
const stripe = canPay === "stripe" || canPay === "stripe_test";
// The chosen moment on the buyer's own clock.
const sendAt = day && clock ? new Date(`${day}T${clock}`) : null;
const ahead = sendAt ? sendAt.getTime() - Date.now() : 0;
const timeOk =
sendAt !== null &&
!Number.isNaN(ahead) &&
ahead > 10 * 60 * 1000 &&
ahead < 365 * 86400 * 1000;
async function submit(e: React.FormEvent) {
e.preventDefault();
@@ -81,6 +107,7 @@ export function GiftForm({
recipient_email_confirm: byEmail ? confirm.trim() : null,
from_name: from.trim() || null,
message: message.trim() || null,
send_at: byEmail && timed && sendAt ? sendAt.toISOString() : null,
},
},
);
@@ -223,6 +250,81 @@ export function GiftForm({
</div>
</div>
)}
{byEmail && (
<div className="gift-when">
<span className="label">Mikor kapja meg?</span>
<div className="gift-when-choices">
<label
className={!timed ? "feedback-kind is-on" : "feedback-kind"}
>
<input
type="radio"
name={`${id}-when`}
checked={!timed}
onChange={() => setTimed(false)}
/>
Fizetés után azonnal
</label>
<label
className={timed ? "feedback-kind is-on" : "feedback-kind"}
>
<input
type="radio"
name={`${id}-when`}
checked={timed}
onChange={() => setTimed(true)}
/>
Időzítve
</label>
{xmas && (
<button
type="button"
className="btn btn-sm"
onClick={() => {
setTimed(true);
setDay(localDay(xmas));
setClock("08:00");
}}
>
Karácsony reggel (dec. 24., 8:00)
</button>
)}
</div>
{timed && (
<div className="gift-when-fields">
<div className="field">
<label htmlFor={`${id}-day`}>Nap</label>
<input
id={`${id}-day`}
className="inp"
type="date"
value={day}
min={localDay(new Date())}
onChange={(e) => setDay(e.target.value)}
/>
</div>
<div className="field">
<label htmlFor={`${id}-clock`}>Időpont</label>
<input
id={`${id}-clock`}
className="inp"
type="time"
step={900}
value={clock}
onChange={(e) => setClock(e.target.value)}
/>
</div>
</div>
)}
<span className={timed && !timeOk ? "msg msg-error" : "hint"}>
{timed
? timeOk
? "A te időd szerint. Addig az Ajándékaim oldalon letöltheted az utalványt, vagy elküldheted azonnal is."
: "Válassz egy jövőbeli időpontot (legfeljebb egy évre előre)."
: "Ha későbbre szánod, időzítsd, vagy válaszd az „Én adom át” lehetőséget."}
</span>
</div>
)}
</fieldset>
<div className="field">
@@ -253,6 +355,9 @@ export function GiftForm({
<span className="muted">
„{chosen.name}” csomag ajándékba
{name.trim() ? `, ${name.trim()} részére` : ""}
{byEmail && timed && sendAt && timeOk
? ` · küldés: ${whenText(sendAt)}`
: ""}
</span>
<strong className="num">{huf(chosen.price_huf)}</strong>
</p>
@@ -261,7 +366,13 @@ export function GiftForm({
<button
type="submit"
className="btn btn-primary"
disabled={busy || !chosen || !emailOk || !name.trim()}
disabled={
busy ||
!chosen ||
!emailOk ||
!name.trim() ||
(byEmail && timed && !timeOk)
}
>
{busy
? stripe