From 382bd31271193f81425097afaa20ef20492e805d Mon Sep 17 00:00:00 2001 From: feco Date: Tue, 24 Nov 2026 13:46:35 +0000 Subject: [PATCH] Christmas gifts and timed gift e-mails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL --- crates/db/migrations/0037_gift_schedule.sql | 6 + crates/email-templates/src/lib.rs | 41 +- crates/gift-card/examples/preview.rs | 1 + crates/gift-card/src/lib.rs | 109 +++++- docs/ajandek.md | 25 +- services/backend/src/routes/auth.rs | 23 +- services/backend/src/routes/gifts.rs | 192 +++++++++- services/backend/src/routes/payments.rs | 10 +- services/backend/src/tests.rs | 78 +++- .../public/img/ajandek-karacsony.webp | Bin 0 -> 43410 bytes .../src/app/admin/ajandekok/AdminGifts.tsx | 356 ++++++++++-------- .../frontend/src/app/ajandek/GiftForm.tsx | 113 +++++- services/frontend/src/app/ajandek/page.tsx | 7 +- .../frontend/src/app/ajandekaim/GiftList.tsx | 31 +- services/frontend/src/app/csomagok/page.tsx | 9 +- services/frontend/src/app/globals.css | 21 ++ services/frontend/src/app/karacsony/page.tsx | 150 ++++++++ services/frontend/src/app/sitemap.ts | 1 + .../frontend/src/components/PaymentReturn.tsx | 11 +- services/frontend/src/lib/season.ts | 30 ++ services/frontend/src/lib/types.ts | 10 + services/worker/src/email.rs | 1 + 22 files changed, 1016 insertions(+), 209 deletions(-) create mode 100644 crates/db/migrations/0037_gift_schedule.sql create mode 100644 services/frontend/public/img/ajandek-karacsony.webp create mode 100644 services/frontend/src/app/karacsony/page.tsx create mode 100644 services/frontend/src/lib/season.ts diff --git a/crates/db/migrations/0037_gift_schedule.sql b/crates/db/migrations/0037_gift_schedule.sql new file mode 100644 index 0000000..449297d --- /dev/null +++ b/crates/db/migrations/0037_gift_schedule.sql @@ -0,0 +1,6 @@ +-- A gift e-mailed later (e.g. on Christmas morning): when (NULL: at once), +-- and the e-mail queued for it, to show whether it went out (the outbox row +-- itself is cleaned up a week after sending). +ALTER TABLE gifts + ADD COLUMN send_at timestamptz, + ADD COLUMN email_id uuid; diff --git a/crates/email-templates/src/lib.rs b/crates/email-templates/src/lib.rs index 7510916..8d98d7e 100644 --- a/crates/email-templates/src/lib.rs +++ b/crates/email-templates/src/lib.rs @@ -334,7 +334,13 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result()); let whom = name(&payload["gift"], "recipient_name"); - (code, to, whom) + // `2026-12-24 08:00`, Budapest clock: when it is e-mailed. + let when = payload["gift"]["send_at"].as_str().and_then(|t| { + let (day, clock) = t.split_once(' ')?; + let clock: String = clock.chars().filter(|c| c.is_ascii_digit() || *c == ':').take(5).collect(); + Some((date(lang, day)?, clock)) + }); + (code, to, whom, when) }); let contents_hu = contents.as_ref().map(|c| format!(" Tartalma: {c}.")).unwrap_or_default(); let contents_en = contents.as_ref().map(|c| format!(" It contains: {c}.")).unwrap_or_default(); @@ -359,9 +365,10 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result Content { + (Lang::Hu, Some((code, to, whom, when))) => Content { subject: format!("Köszönjük a vásárlást: {package} (ajándék)"), preheader: Some(match &to { + Some(e) if when.is_some() => format!("Az ajándékot időzítve küldjük el ide: {e}."), Some(e) => format!("Az ajándékot elküldtük ide: {e}."), None => "Az ajándékutalványt csatoltuk ehhez a levélhez.".into(), }), @@ -370,7 +377,10 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result format!("Az ajándékkódot az utalvánnyal együtt elküldtük ide: {e}. Ha nem e-mailben adnád át, az Ajándékaim oldalon letöltheted az utalványt PDF-ben."), + Some(e) => match &when { + Some((day, clock)) => format!("Az ajándékkódot az utalvánnyal együtt {day}, {clock}-kor küldjük el ide: {e}. Addig az Ajándékaim oldalon letöltheted az utalványt PDF-ben, vagy elküldheted azonnal is."), + None => format!("Az ajándékkódot az utalvánnyal együtt elküldtük ide: {e}. Ha nem e-mailben adnád át, az Ajándékaim oldalon letöltheted az utalványt PDF-ben."), + }, None => "Az ajándékutalványt PDF-ben csatoltuk ehhez a levélhez, és az Ajándékaim oldalon is letöltheted: kinyomtathatod, vagy továbbküldheted annak, akinek szánod.".into(), } ), @@ -409,7 +419,7 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result Content { + (Lang::En, Some((code, to, whom, when))) => Content { subject: format!("Thank you for your purchase: {package} (gift)"), preheader: Some(match &to { Some(e) => format!("We sent the gift to {e}."), @@ -420,7 +430,10 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result format!("We sent the gift code with the gift card to {e}. To hand it over another way, download the card as a PDF on the My gifts page."), + Some(e) => match &when { + Some((day, clock)) => format!("We send the gift code with the gift card to {e} on {day} at {clock}. Until then you can download the card on the My gifts page, or send it at once."), + None => format!("We sent the gift code with the gift card to {e}. To hand it over another way, download the card as a PDF on the My gifts page."), + }, None => "The gift card is attached to this e-mail as a PDF, and you can download it on the My gifts page: print it, or forward it to the person it is for.".into(), } ), @@ -459,16 +472,21 @@ fn gift_package(lang: Lang, payload: &Value, url: String) -> Result()); let from = name(payload, "from_name"); let to = name(payload, "recipient_name"); + // Bought for Christmas: said so, with the wishes. + let christmas = payload["christmas_year"].as_i64().is_some(); + let xmas = if christmas { "karácsonyi " } else { "" }; Ok(match lang { Lang::Hu => Content { subject: match &from { - Some(f) => format!("{f} ajándékot küldött neked: „{package}” csomag"), + Some(f) => format!("{f} {xmas}ajándékot küldött neked: „{package}” csomag"), + None if christmas => format!("Karácsonyi ajándékot kaptál: „{package}” csomag a Sorsfonalakon"), None => format!("Ajándékot kaptál: „{package}” csomag a Sorsfonalakon"), }, preheader: Some("Születési képlet és személyre szóló elemzések: a kód beváltásával a tiéd.".into()), greeting: to.as_ref().map_or_else(|| "Szia!".into(), |t| format!("Szia {t}!")), intro: format!( - "{} egy „{package}” csomagot a Sorsfonalakon.{}", + "{}{} egy „{package}” csomagot a Sorsfonalakon.{}", + if christmas { "Boldog karácsonyt! " } else { "" }, match &from { Some(f) => format!("{f} ajándékozott neked"), None => "Ajándékba kaptál".into(), @@ -497,6 +515,7 @@ fn gift_package(lang: Lang, payload: &Value, url: String) -> Result Content { subject: match &from { + Some(f) if christmas => format!("{f} sent you a Christmas gift: the “{package}” package"), Some(f) => format!("{f} sent you a gift: the “{package}” package"), None => format!("A gift for you: the “{package}” package on Sorsfonalak"), }, @@ -1021,6 +1040,11 @@ mod tests { ); assert!(hu.html.contains("<b>Ölel</b>") && hu.html.contains(">ABCD-EFGH-JKMN")); assert!(hu.text.contains("PDF-ben is csatoltuk") && hu.text.contains("mert Ági a Sorsfonalakon")); + let mut xmas = payload.clone(); + xmas["christmas_year"] = 2027.into(); + let hu = render("gift_package", "hu", &xmas).unwrap(); + assert_eq!(hu.subject, "Ági karácsonyi ajándékot küldött neked: „Páros” csomag"); + assert!(hu.text.contains("Boldog karácsonyt! Ági ajándékozott neked")); let anonymous = serde_json::json!({"url": "u", "package_name": "Család", "promo_code": "X1-