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:
@@ -173,6 +173,26 @@ fn invitation(lang: Lang, payload: &Value, url: String) -> Result<Content, Templ
|
||||
let until_hu = until.trim_end_matches('.');
|
||||
let unsubscribe_url = field(payload, "unsubscribe_url")?;
|
||||
let unsubscribe_post_url = field(payload, "unsubscribe_post_url")?;
|
||||
// A package that comes with the invitation, and its promo code.
|
||||
let gift = name(payload, "package_name").zip(
|
||||
payload["promo_code"]
|
||||
.as_str()
|
||||
.map(|c| c.chars().filter(|c| c.is_ascii_alphanumeric() || *c == '-').take(40).collect::<String>())
|
||||
.filter(|c| !c.is_empty()),
|
||||
);
|
||||
let gift_line = |hu: bool| {
|
||||
gift.as_ref().map(|(package, code)| {
|
||||
if hu {
|
||||
format!(
|
||||
" Ajándékba egy „{package}” csomagot is kapsz: a regisztrációval magától jóváíródik. Ha mégis kellene, a promókódod: {code}."
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
" You also get the “{package}” package as a gift: it is added when you sign up. Should you need it, your promo code is {code}."
|
||||
)
|
||||
}
|
||||
})
|
||||
};
|
||||
Ok(match lang {
|
||||
Lang::Hu => Content {
|
||||
subject: match &inviter {
|
||||
@@ -188,7 +208,7 @@ fn invitation(lang: Lang, payload: &Value, url: String) -> Result<Content, Templ
|
||||
None => {
|
||||
"Meghívót kaptál a Sorsfonalakra. Az oldal egyelőre zártkörű: csak meghívóval lehet belépni.".into()
|
||||
}
|
||||
},
|
||||
} + &gift_line(true).unwrap_or_default(),
|
||||
quote: message,
|
||||
points: Some((
|
||||
"Mit találsz ott?",
|
||||
@@ -226,7 +246,7 @@ fn invitation(lang: Lang, payload: &Value, url: String) -> Result<Content, Templ
|
||||
intro: match &inviter {
|
||||
Some(n) => format!("{n} invited you to Sorsfonalak. The site is invitation-only for now."),
|
||||
None => "You are invited to Sorsfonalak. The site is invitation-only for now.".into(),
|
||||
},
|
||||
} + &gift_line(false).unwrap_or_default(),
|
||||
quote: message,
|
||||
points: Some((
|
||||
"What you will find there:",
|
||||
@@ -468,6 +488,14 @@ mod tests {
|
||||
assert!(en.text.contains("valid until 17 December 2026") && !en.text.contains("> "));
|
||||
assert!(!en.html.contains("border-left"));
|
||||
|
||||
let mut gift = invitation_payload();
|
||||
gift["package_name"] = json!("Páros");
|
||||
gift["promo_code"] = json!("ABCD-EFGH-JKLM");
|
||||
let hu = render("invitation", "hu", &gift).unwrap();
|
||||
assert!(hu.text.contains("Ajándékba egy „Páros” csomagot is kapsz"), "{}", hu.text);
|
||||
assert!(hu.html.contains("ABCD-EFGH-JKLM"));
|
||||
assert!(!render("invitation", "hu", &invitation_payload()).unwrap().text.contains("Ajándék"));
|
||||
|
||||
let mut broken = invitation_payload();
|
||||
broken["unsubscribe_url"] = Value::Null;
|
||||
assert_eq!(render("invitation", "hu", &broken), Err(TemplateError::MissingField("unsubscribe_url")));
|
||||
|
||||
Reference in New Issue
Block a user