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