"use client"; import { useCallback, useEffect, useState } from "react"; import { api, errorText } from "@/lib/api"; import { formatDate } from "@/lib/astro"; import type { AdminInvitation, InvitationResult, WaitlistEntry } from "@/lib/types"; const MAX_MESSAGE = 300; const STATUS: Record = { pending: "Függőben", accepted: "Elfogadva", expired: "Lejárt", revoked: "Visszavonva", }; const MAIL: Record = { sent: "Elküldve", queued: "Sorban vár", failed: "Sikertelen", archived: "Elküldve (archív)", }; const RESULT: Record = { invited: "meghívva", invalid: "érvénytelen cím", already_user: "már felhasználó", already_invited: "már van élő meghívója (újraküldés a listában)", opted_out: "leiratkozott a meghívókról", }; interface ListData { invitations: AdminInvitation[]; waitlist: WaitlistEntry[]; signup_mode: "invite" | "open"; } function CopyLink({ url }: { url: string }) { const [copied, setCopied] = useState(false); return ( ); } /** Addresses from free text: one per line, or separated by commas, semicolons or spaces. */ function parseEmails(text: string): string[] { return text .split(/[\s,;]+/) .map((s) => s.trim()) .filter(Boolean); } export function AdminInvitations() { const [data, setData] = useState(null); const [error, setError] = useState(null); const load = useCallback(async () => { try { setData(await api("/admin/invitations")); setError(null); } catch (e) { setError(errorText(e)); } }, []); useEffect(() => { load(); }, [load]); return (
{data?.signup_mode === "open" && (

A regisztráció most nyitott (SIGNUP_MODE=open): bárki beléphet, a meghívó csak értesítés.

)} {error && (

{error}

)} {data && } {data && }
); } function InviteForm({ onSent }: { onSent: () => Promise }) { const [emails, setEmails] = useState(""); const [message, setMessage] = useState(""); const [locale, setLocale] = useState("hu"); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [results, setResults] = useState(null); const count = parseEmails(emails).length; async function submit(e: React.FormEvent) { e.preventDefault(); setBusy(true); setError(null); setResults(null); try { const res = await api<{ results: InvitationResult[] }>("/admin/invitations", { body: { emails: parseEmails(emails), message: message.trim() || null, locale }, }); setResults(res.results); if (res.results.some((r) => r.status === "invited")) setEmails(""); await onSent(); } catch (err) { setError(errorText(err)); } finally { setBusy(false); } } return (

Új meghívó