Invitation page shows its gift package; person invites: e-mail and link only
- 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:
@@ -552,6 +552,7 @@ pub async fn preview(
|
|||||||
pub async fn public_view(State(state): St, Path(token): Path<String>) -> ApiResult<Json<Value>> {
|
pub async fn public_view(State(state): St, Path(token): Path<String>) -> ApiResult<Json<Value>> {
|
||||||
#[derive(sqlx::FromRow)]
|
#[derive(sqlx::FromRow)]
|
||||||
struct Landing {
|
struct Landing {
|
||||||
|
id: Uuid,
|
||||||
inviter: Option<String>,
|
inviter: Option<String>,
|
||||||
message: Option<String>,
|
message: Option<String>,
|
||||||
expires_at: OffsetDateTime,
|
expires_at: OffsetDateTime,
|
||||||
@@ -559,7 +560,7 @@ pub async fn public_view(State(state): St, Path(token): Path<String>) -> ApiResu
|
|||||||
revoked_at: Option<OffsetDateTime>,
|
revoked_at: Option<OffsetDateTime>,
|
||||||
}
|
}
|
||||||
let l: Landing = sqlx::query_as(
|
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 \
|
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",
|
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)
|
.fetch_optional(&state.db)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(ApiError::NotFound("invitation"))?;
|
.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!({
|
Ok(Json(json!({
|
||||||
|
"gift": gift,
|
||||||
"inviter_name": l.inviter,
|
"inviter_name": l.inviter,
|
||||||
"message": l.message,
|
"message": l.message,
|
||||||
"status": status(l.accepted_at, l.revoked_at, l.expires_at),
|
"status": status(l.accepted_at, l.revoked_at, l.expires_at),
|
||||||
|
|||||||
@@ -1772,6 +1772,7 @@ async fn invitation_only_signup(pool: PgPool) {
|
|||||||
);
|
);
|
||||||
let r = app.get(&format!("/v1/public/invitations/{guest_token}"), None).await;
|
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["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
|
// 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;
|
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;
|
let list = app.get("/v1/admin/invitations", Some(&admin)).await.body;
|
||||||
assert_eq!(list["invitations"][0]["package"]["name"], "Páros");
|
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
|
// revoking an invitation withdraws its code
|
||||||
let r = app.call("DELETE", &format!("/v1/admin/invitations/{other_id}"), Some(&admin), None).await;
|
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 { ZodiacWheel } from "@/components/ZodiacWheel";
|
||||||
import { BACKEND_URL, getMe } from "@/lib/server";
|
import { BACKEND_URL, getMe } from "@/lib/server";
|
||||||
import { formatDate } from "@/lib/astro";
|
import { formatDate } from "@/lib/astro";
|
||||||
|
import { contents } from "@/lib/packageContents";
|
||||||
import type { InvitationLanding, PublicConfig } from "@/lib/types";
|
import type { InvitationLanding, PublicConfig } from "@/lib/types";
|
||||||
|
|
||||||
import { AppleLogin } from "./AppleLogin";
|
import { AppleLogin } from "./AppleLogin";
|
||||||
@@ -79,6 +80,19 @@ function InvitationCard({
|
|||||||
{invitation.inviter_name ? <strong>{invitation.inviter_name}</strong> : "Valaki"} meghívott a Sorsfonalakra.
|
{invitation.inviter_name ? <strong>{invitation.inviter_name}</strong> : "Valaki"} meghívott a Sorsfonalakra.
|
||||||
</p>
|
</p>
|
||||||
{invitation.message && <blockquote className="invite-quote">{invitation.message}</blockquote>}
|
{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 }}>
|
<p className="hint" style={{ margin: 0 }}>
|
||||||
Bármelyik {apple ? "Google- vagy Apple-fiókoddal" : "Google-fiókoddal"}
|
Bármelyik {apple ? "Google- vagy Apple-fiókoddal" : "Google-fiókoddal"}
|
||||||
{password ? ", vagy e-mail-címmel regisztrálva" : ""} elfogadhatod. Érvényes:{" "}
|
{password ? ", vagy e-mail-címmel regisztrálva" : ""} elfogadhatod. Érvényes:{" "}
|
||||||
|
|||||||
@@ -658,6 +658,11 @@ a.pair-row:hover strong { color: var(--gold); }
|
|||||||
|
|
||||||
/* Invitations */
|
/* Invitations */
|
||||||
.invite-card { display: flex; flex-direction: column; gap: 8px; }
|
.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 {
|
.invite-quote {
|
||||||
margin: 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--gold);
|
margin: 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--gold);
|
||||||
font-style: italic; white-space: pre-line; color: var(--ink);
|
font-style: italic; white-space: pre-line; color: var(--ink);
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ export function InvitePerson() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (created) {
|
if (created) {
|
||||||
const text = `Nézzük meg, mennyire illünk össze! ${created.url}`;
|
|
||||||
return (
|
return (
|
||||||
<div className="field invite-done" style={{ gap: 12 }}>
|
<div className="field invite-done" style={{ gap: 12 }}>
|
||||||
<p className="msg msg-ok" role="status">
|
<p className="msg msg-ok" role="status">
|
||||||
@@ -79,26 +78,6 @@ export function InvitePerson() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-actions">
|
<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)}>
|
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setCreated(null)}>
|
||||||
Újabb meghívó
|
Újabb meghívó
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -5,22 +5,11 @@ import { useRouter } from "next/navigation";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { api, errorText } from "@/lib/api";
|
import { api, errorText } from "@/lib/api";
|
||||||
|
import { contents } from "@/lib/packageContents";
|
||||||
import type { Package, PayMethod, PublicConfig } from "@/lib/types";
|
import type { Package, PayMethod, PublicConfig } from "@/lib/types";
|
||||||
|
|
||||||
export const huf = (n: number) => `${n.toLocaleString("hu-HU")} Ft`;
|
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
|
* 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
|
* 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;
|
||||||
|
}
|
||||||
@@ -484,6 +484,8 @@ export type InvitationStatus = "pending" | "accepted" | "expired" | "revoked";
|
|||||||
|
|
||||||
/** What an invitation link shows before login. */
|
/** What an invitation link shows before login. */
|
||||||
export interface InvitationLanding {
|
export interface InvitationLanding {
|
||||||
|
/** The package that comes with it (only admins attach one). */
|
||||||
|
gift: Package | null;
|
||||||
inviter_name: string | null;
|
inviter_name: string | null;
|
||||||
message: string | null;
|
message: string | null;
|
||||||
status: InvitationStatus;
|
status: InvitationStatus;
|
||||||
|
|||||||
Reference in New Issue
Block a user