diff --git a/services/backend/src/routes/invitations.rs b/services/backend/src/routes/invitations.rs index 0025eb0..0cb84be 100644 --- a/services/backend/src/routes/invitations.rs +++ b/services/backend/src/routes/invitations.rs @@ -552,6 +552,7 @@ pub async fn preview( pub async fn public_view(State(state): St, Path(token): Path) -> ApiResult> { #[derive(sqlx::FromRow)] struct Landing { + id: Uuid, inviter: Option, message: Option, expires_at: OffsetDateTime, @@ -559,7 +560,7 @@ pub async fn public_view(State(state): St, Path(token): Path) -> ApiResu revoked_at: Option, } 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) -> 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 = 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), diff --git a/services/backend/src/tests.rs b/services/backend/src/tests.rs index ff99f03..2b6a61e 100644 --- a/services/backend/src/tests.rs +++ b/services/backend/src/tests.rs @@ -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; diff --git a/services/frontend/src/app/belepes/page.tsx b/services/frontend/src/app/belepes/page.tsx index 93650e2..41b8291 100644 --- a/services/frontend/src/app/belepes/page.tsx +++ b/services/frontend/src/app/belepes/page.tsx @@ -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 ? {invitation.inviter_name} : "Valaki"} meghívott a Sorsfonalakra.

{invitation.message &&
{invitation.message}
} + {invitation.gift && ( +
+

+ Ajándékba kapod a „{invitation.gift.name}” csomagot, a regisztrációval magától + jóváíródik: +

+
    + {contents(invitation.gift).map((line) => ( +
  • {line}
  • + ))} +
+
+ )}

Bármelyik {apple ? "Google- vagy Apple-fiókoddal" : "Google-fiókoddal"} {password ? ", vagy e-mail-címmel regisztrálva" : ""} elfogadhatod. Érvényes:{" "} diff --git a/services/frontend/src/app/globals.css b/services/frontend/src/app/globals.css index 2e70fcc..41b8971 100644 --- a/services/frontend/src/app/globals.css +++ b/services/frontend/src/app/globals.css @@ -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); diff --git a/services/frontend/src/components/InvitePerson.tsx b/services/frontend/src/components/InvitePerson.tsx index 2410eb6..b15969d 100644 --- a/services/frontend/src/components/InvitePerson.tsx +++ b/services/frontend/src/components/InvitePerson.tsx @@ -56,7 +56,6 @@ export function InvitePerson() { } if (created) { - const text = `Nézzük meg, mennyire illünk össze! ${created.url}`; return (

@@ -79,26 +78,6 @@ export function InvitePerson() {

- {typeof navigator !== "undefined" && "share" in navigator && ( - - )} - - WhatsApp - - - Facebook - diff --git a/services/frontend/src/components/PackageCards.tsx b/services/frontend/src/components/PackageCards.tsx index 34ce334..bdea588 100644 --- a/services/frontend/src/components/PackageCards.tsx +++ b/services/frontend/src/components/PackageCards.tsx @@ -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 diff --git a/services/frontend/src/lib/packageContents.ts b/services/frontend/src/lib/packageContents.ts new file mode 100644 index 0000000..d38fb7d --- /dev/null +++ b/services/frontend/src/lib/packageContents.ts @@ -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; +} diff --git a/services/frontend/src/lib/types.ts b/services/frontend/src/lib/types.ts index e4b326a..8b5cfa1 100644 --- a/services/frontend/src/lib/types.ts +++ b/services/frontend/src/lib/types.ts @@ -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;