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,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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user