Inviting a person to compare charts
The new person page offers 'Adatok megadása' (typed-in data, uses a slot) or 'Meghívom': a 'how compatible are we?' link with an optional name, e-mail and message (no links, 300 chars), shareable by copy, the phone's share menu, WhatsApp or Facebook. With an address we e-mail it too (at most 10 a day per user, opted-out addresses skipped, unsubscribe link included). The invitee lands on /meghivas/<token>, signs in, gives their own birth data if needed and gets the comparison; the inviter is told and lists pending invitations (revocable) on the persons page. No person slot is used. Also: the accepted e-mail links to /osszevetesek/<id>, and the cross grid no longer breaks on another user's chart (no highlights there). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
|
||||
const MAX_MESSAGE = 300;
|
||||
|
||||
interface Created {
|
||||
url: string;
|
||||
emailed: boolean;
|
||||
email: string | null;
|
||||
label: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invites someone to compare charts instead of typing in their birth data:
|
||||
* they enter their own data, and both see the comparison (not each other's
|
||||
* birth data). No person slot is used.
|
||||
*/
|
||||
export function InvitePerson() {
|
||||
const [label, setLabel] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [created, setCreated] = useState<Created | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
setCreated(
|
||||
await api<Created>("/invites", {
|
||||
body: { label: label.trim() || null, email: email.trim() || null, message: message.trim() || null },
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
setError(errorText(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function copy() {
|
||||
if (!created) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(created.url);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
} catch {
|
||||
setError("Nem sikerült másolni; jelöld ki a linket, és másold kézzel.");
|
||||
}
|
||||
}
|
||||
|
||||
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">
|
||||
{created.emailed
|
||||
? `Elküldtük a meghívót ide: ${created.email}. A linket te is továbbküldheted.`
|
||||
: created.email
|
||||
? `Ez a cím nem kér levelet tőlünk, ezért nem írtunk neki. Küldd el neki te a linket.`
|
||||
: "Kész a meghívó. Küldd el a linket annak, akit meghívsz."}
|
||||
</p>
|
||||
<div className="share-link">
|
||||
<input
|
||||
className="inp"
|
||||
readOnly
|
||||
value={created.url}
|
||||
aria-label="Meghívó link"
|
||||
onFocus={(e) => e.currentTarget.select()}
|
||||
/>
|
||||
<button type="button" className="btn btn-sm" onClick={copy}>
|
||||
{copied ? "Kimásolva" : "Másolás"}
|
||||
</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>
|
||||
</div>
|
||||
<p className="hint">
|
||||
A meghívó 14 napig érvényes. Amikor elfogadja, levelet kapsz, és az összevetés megjelenik az Összevetéseid
|
||||
között.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="field" style={{ gap: 14 }} onSubmit={submit}>
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label htmlFor="invite-label">Kit hívsz meg?</label>
|
||||
<input
|
||||
id="invite-label"
|
||||
className="inp"
|
||||
value={label}
|
||||
maxLength={80}
|
||||
onChange={(e) => setLabel(e.target.value)}
|
||||
placeholder="pl. Anna"
|
||||
/>
|
||||
<span className="hint">Csak te látod, a meghívóid között.</span>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="invite-email">E-mail-címe (nem kötelező)</label>
|
||||
<input
|
||||
id="invite-email"
|
||||
className="inp"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="anna@pelda.hu"
|
||||
autoComplete="off"
|
||||
/>
|
||||
<span className="hint">Ha megadod, levélben is elküldjük neki.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="invite-message">Üzenet (nem kötelező)</label>
|
||||
<textarea
|
||||
id="invite-message"
|
||||
className="inp"
|
||||
rows={3}
|
||||
maxLength={MAX_MESSAGE}
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
placeholder="Szia! Nézzük meg, mennyire illünk össze."
|
||||
/>
|
||||
<span className="hint">
|
||||
{message.length}/{MAX_MESSAGE} karakter, link nélkül.
|
||||
</span>
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy}>
|
||||
{busy ? "Készül…" : "Meghívó készítése"}
|
||||
</button>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { PersonInvite } from "@/lib/types";
|
||||
|
||||
/** The user's "how compatible are we?" invitations: waiting ones (revocable) and accepted ones. */
|
||||
export function PendingInvites() {
|
||||
const [invites, setInvites] = useState<PersonInvite[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
setInvites((await api<{ invites: PersonInvite[] }>("/invites")).invites);
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
async function revoke(i: PersonInvite) {
|
||||
if (!window.confirm(`Visszavonod a meghívót${i.label ? ` (${i.label})` : ""}? A link nem fog működni.`)) return;
|
||||
try {
|
||||
await api(`/invites/${i.id}`, { method: "DELETE" });
|
||||
await load();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}
|
||||
|
||||
// Waiting ones, and the accepted ones of the last 30 days.
|
||||
const recent = Date.now() - 30 * 86_400_000;
|
||||
const shown = (invites ?? []).filter(
|
||||
(i) => i.status === "pending" || (i.status === "accepted" && i.accepted_at && Date.parse(i.accepted_at) > recent),
|
||||
);
|
||||
if (!error && shown.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section className="card" aria-labelledby="invites-title" style={{ gap: 12 }}>
|
||||
<h2 id="invites-title">Meghívóid</h2>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<ul className="invite-list">
|
||||
{shown.map((i) => (
|
||||
<li key={i.id}>
|
||||
<span className="invite-who">
|
||||
<strong>{i.label ?? i.email ?? "Meghívó"}</strong>
|
||||
{i.label && i.email && <span className="hint">{i.email}</span>}
|
||||
</span>
|
||||
{i.status === "pending" ? (
|
||||
<>
|
||||
<span className="hint">
|
||||
Elküldve {formatDate(i.created_at)}, érvényes {formatDate(i.expires_at).replace(/\.$/, "")}-ig
|
||||
</span>
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => revoke(i)}>
|
||||
Visszavonás
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span className="hint">
|
||||
Elfogadta{i.accepted_by ? `: ${i.accepted_by}` : ""} · {formatDate(i.accepted_at)}
|
||||
</span>
|
||||
{i.synastry_id && (
|
||||
<Link href={`/osszevetesek/${i.synastry_id}`} className="btn btn-sm">
|
||||
Összevetés
|
||||
</Link>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ASPECTS, POINTS, SIGNS, dms, orbText, pointName, signName } from "@/lib/astro";
|
||||
import { sideTimeKnown } from "@/lib/synastry";
|
||||
import type { HouseOverlay, InterAspect, Synastry, SynastryResult } from "@/lib/types";
|
||||
|
||||
import { GRID_POINTS, Pos } from "./ChartTables";
|
||||
@@ -47,7 +48,7 @@ const GRID_ANGLES: [string, string][] = [
|
||||
function gridPoints(s: Synastry["chart1"]): [string, string][] {
|
||||
const present = new Set(s.chart.points.map((p) => p.id));
|
||||
const rows: [string, string][] = GRID_POINTS.filter((id) => present.has(id)).map((id) => [id, POINTS[id]?.glyph ?? id]);
|
||||
if (s.highlights.time_known) {
|
||||
if (sideTimeKnown(s)) {
|
||||
for (const [key, label] of GRID_ANGLES) if (s.chart.angles?.[key]) rows.push([key, label]);
|
||||
}
|
||||
return rows;
|
||||
|
||||
Reference in New Issue
Block a user