Invitation page shows its gift package; person invites: e-mail and link only
CI / test (push) Successful in 2m5s
CI / build (push) Skipped
CI / deploy (push) Skipped

- The admin invitation's page lists the package that comes with it (the
  public invitation view returns it; the promo code stays in the e-mail).
- Inviting a person: no Facebook, WhatsApp or share-sheet buttons, only the
  e-mail and copying the link.
- contents() moved to lib/packageContents so server pages can use it.

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-23 10:05:19 +00:00
co-authored by Claude Opus 5.5
parent 169fb9c85d
commit a986cf4edd
8 changed files with 51 additions and 34 deletions
+11 -1
View File
@@ -552,6 +552,7 @@ pub async fn preview(
pub async fn public_view(State(state): St, Path(token): Path<String>) -> ApiResult<Json<Value>> {
#[derive(sqlx::FromRow)]
struct Landing {
id: Uuid,
inviter: Option<String>,
message: Option<String>,
expires_at: OffsetDateTime,
@@ -559,7 +560,7 @@ pub async fn public_view(State(state): St, Path(token): Path<String>) -> ApiResu
revoked_at: Option<OffsetDateTime>,
}
let l: Landing = sqlx::query_as(
"SELECT u.display_name AS inviter, i.message, i.expires_at, i.accepted_at, i.revoked_at \
"SELECT i.id, u.display_name AS inviter, i.message, i.expires_at, i.accepted_at, i.revoked_at \
FROM invitation_tokens t JOIN invitations i ON i.id = t.invitation_id \
LEFT JOIN users u ON u.id = i.invited_by WHERE t.token_hash = $1",
)
@@ -567,7 +568,16 @@ pub async fn public_view(State(state): St, Path(token): Path<String>) -> ApiResu
.fetch_optional(&state.db)
.await?
.ok_or(ApiError::NotFound("invitation"))?;
// The package that comes with it (only admins attach one); its code stays in the e-mail.
let gift: Option<String> = sqlx::query_scalar(
"SELECT package FROM promo_codes WHERE invitation_id = $1 AND redeemed_at IS NULL AND revoked_at IS NULL",
)
.bind(l.id)
.fetch_optional(&state.db)
.await?;
let gift = gift.as_deref().and_then(packages::find).map_or(Value::Null, |p| p.view());
Ok(Json(json!({
"gift": gift,
"inviter_name": l.inviter,
"message": l.message,
"status": status(l.accepted_at, l.revoked_at, l.expires_at),
+5
View File
@@ -1772,6 +1772,7 @@ async fn invitation_only_signup(pool: PgPool) {
);
let r = app.get(&format!("/v1/public/invitations/{guest_token}"), None).await;
assert_eq!((r.body["inviter_name"].as_str(), r.body["status"].as_str()), (Some("Admin"), Some("pending")));
assert_eq!(r.body["gift"], Value::Null);
// a resend: not too soon, then with a new link; the old one keeps working
let r = app.post(&format!("/v1/admin/invitations/{guest_id}/resend"), Some(&admin), json!({})).await;
@@ -2340,6 +2341,10 @@ async fn an_invitation_brings_its_package_and_codes_fill_up(pool: PgPool) {
);
let list = app.get("/v1/admin/invitations", Some(&admin)).await.body;
assert_eq!(list["invitations"][0]["package"]["name"], "Páros");
// so does the invitation's page (without the code)
let page = app.get(&format!("/v1/public/invitations/{guest_token}"), None).await.body;
assert_eq!((&page["gift"]["name"], &page["gift"]["id"]), (&json!("Páros"), &json!("couple")), "{page}");
assert!(!page.to_string().contains(guest["promo_code"].as_str().unwrap()));
// revoking an invitation withdraws its code
let r = app.call("DELETE", &format!("/v1/admin/invitations/{other_id}"), Some(&admin), None).await;
@@ -6,6 +6,7 @@ import { Logo } from "@/components/SiteHeader";
import { ZodiacWheel } from "@/components/ZodiacWheel";
import { BACKEND_URL, getMe } from "@/lib/server";
import { formatDate } from "@/lib/astro";
import { contents } from "@/lib/packageContents";
import type { InvitationLanding, PublicConfig } from "@/lib/types";
import { AppleLogin } from "./AppleLogin";
@@ -79,6 +80,19 @@ function InvitationCard({
{invitation.inviter_name ? <strong>{invitation.inviter_name}</strong> : "Valaki"} meghívott a Sorsfonalakra.
</p>
{invitation.message && <blockquote className="invite-quote">{invitation.message}</blockquote>}
{invitation.gift && (
<div className="invite-gift">
<p style={{ margin: 0 }}>
Ajándékba kapod a <strong>„{invitation.gift.name}”</strong> csomagot, a regisztrációval magától
jóváíródik:
</p>
<ul>
{contents(invitation.gift).map((line) => (
<li key={line}>{line}</li>
))}
</ul>
</div>
)}
<p className="hint" style={{ margin: 0 }}>
Bármelyik {apple ? "Google- vagy Apple-fiókoddal" : "Google-fiókoddal"}
{password ? ", vagy e-mail-címmel regisztrálva" : ""} elfogadhatod. Érvényes:{" "}
+5
View File
@@ -658,6 +658,11 @@ a.pair-row:hover strong { color: var(--gold); }
/* Invitations */
.invite-card { display: flex; flex-direction: column; gap: 8px; }
.invite-gift {
border: 1px solid rgba(217, 180, 106, 0.45); background: rgba(217, 180, 106, 0.07); border-radius: 10px;
padding: 10px 14px; font-size: 14px;
}
.invite-gift ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); }
.invite-quote {
margin: 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--gold);
font-style: italic; white-space: pre-line; color: var(--ink);
@@ -56,7 +56,6 @@ export function InvitePerson() {
}
if (created) {
const text = `Nézzük meg, mennyire illünk össze! ${created.url}`;
return (
<div className="field invite-done" style={{ gap: 12 }}>
<p className="msg msg-ok" role="status">
@@ -79,26 +78,6 @@ export function InvitePerson() {
</button>
</div>
<div className="form-actions">
{typeof navigator !== "undefined" && "share" in navigator && (
<button
type="button"
className="btn btn-sm btn-primary"
onClick={() => navigator.share({ text: "Nézzük meg, mennyire illünk össze!", url: created.url }).catch(() => {})}
>
Küldés…
</button>
)}
<a className="btn btn-sm" href={`https://wa.me/?text=${encodeURIComponent(text)}`} target="_blank" rel="noopener noreferrer">
WhatsApp
</a>
<a
className="btn btn-sm"
href={`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(created.url)}`}
target="_blank"
rel="noopener noreferrer"
>
Facebook
</a>
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setCreated(null)}>
Újabb meghívó
</button>
@@ -5,22 +5,11 @@ import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { api, errorText } from "@/lib/api";
import { contents } from "@/lib/packageContents";
import type { Package, PayMethod, PublicConfig } from "@/lib/types";
export const huf = (n: number) => `${n.toLocaleString("hu-HU")} Ft`;
/** What a package contains, as short lines. */
export function contents(p: Package): string[] {
const lines: string[] = [];
if (p.natal) lines.push(`${p.natal} részletes képletelemzés`);
if (p.synastry) lines.push(`${p.synastry} kapcsolati elemzés`);
if (p.forecast) lines.push(`${p.forecast} éves előrejelzés`);
if (p.persons) lines.push(`${p.persons} személy felvétele`);
if (p.questions) lines.push(`${p.questions} kérdés az elemzéseidről`);
if (p.tarot) lines.push(`${p.tarot} kártyajóslás`);
return lines;
}
/**
* Package cards with a buy button. Bigger packages show what they save and
* how little more they cost than the previous one. With Stripe the button
@@ -0,0 +1,13 @@
import type { Package } from "./types";
/** What a package contains, as short lines. */
export function contents(p: Package): string[] {
const lines: string[] = [];
if (p.natal) lines.push(`${p.natal} részletes képletelemzés`);
if (p.synastry) lines.push(`${p.synastry} kapcsolati elemzés`);
if (p.forecast) lines.push(`${p.forecast} éves előrejelzés`);
if (p.persons) lines.push(`${p.persons} személy felvétele`);
if (p.questions) lines.push(`${p.questions} kérdés az elemzéseidről`);
if (p.tarot) lines.push(`${p.tarot} kártyajóslás`);
return lines;
}
+2
View File
@@ -484,6 +484,8 @@ export type InvitationStatus = "pending" | "accepted" | "expired" | "revoked";
/** What an invitation link shows before login. */
export interface InvitationLanding {
/** The package that comes with it (only admins attach one). */
gift: Package | null;
inviter_name: string | null;
message: string | null;
status: InvitationStatus;