"use client"; import { useEffect, useId, useRef, useState } from "react"; import { ArrowUpRight, LockKeyhole, Sparkles, X } from "lucide-react"; import { archiveJoinLead } from "@social/lib/joinArchive"; import { markJoinPayIntent } from "@social/lib/joinFlow"; import { loginWithEmail } from "@social/lib/socialSession"; import { useSocialConfig } from "./SocialExperience"; import { socialTx } from "@social/lib/socialTx"; type Props = { open: boolean; onClose: () => void; }; const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; /** * 加群:填邮箱 → 调起门户统一支付 * PC/H5 → zpay;微信内 H5 → xpay(xorpay);小程序 WebView 提示走虚拟支付 */ export default function JoinPayModal({ open, onClose }: Props) { return open ? : null; } function JoinPaySheet({ onClose }: Pick) { const titleId = useId(); const descriptionId = useId(); const errorId = useId(); const dialogRef = useRef(null); const inputRef = useRef(null); const config = useSocialConfig(); const rawFen = Number(config.copy?.vipPriceFen); const priceFen = Number.isFinite(rawFen) && rawFen >= 0 ? Math.round(rawFen) : 10; const [email, setEmail] = useState(() => { try { return localStorage.getItem("userEmail") || ""; } catch { return ""; } }); const [busy, setBusy] = useState(false); const [err, setErr] = useState(""); useEffect(() => { const dialog = dialogRef.current; const opener = document.activeElement as HTMLElement | null; const previousOverflow = document.body.style.overflow; dialog?.showModal(); inputRef.current?.focus(); document.body.style.overflow = "hidden"; return () => { dialog?.close(); document.body.style.overflow = previousOverflow; opener?.focus(); }; }, []); const submit = async () => { if (busy) return; const value = email.trim().toLowerCase(); if (!EMAIL_RE.test(value)) { setErr("请输入有效邮箱"); return; } setErr(""); setBusy(true); try { loginWithEmail(value); markJoinPayIntent(); // Must await before pay redirect — otherwise fetch is aborted and admin sees no lead await archiveJoinLead("email_submit", { priceFen, intent: "pay", }); const inMiniProgram = /miniProgram/i.test(navigator.userAgent) || (window as unknown as { __wxjs_environment?: string }) .__wxjs_environment === "miniprogram"; if (inMiniProgram) { window.location.href = "/vip"; return; } const { triggerPay } = await import("@vip/app/lib/triggerPay"); const returnUrl = `${window.location.origin}/paid?join=1`; await triggerPay(undefined, { returnUrl }); void archiveJoinLead("pay_launched", { priceFen }); onClose(); } catch (e) { setErr(e instanceof Error ? e.message : "支付唤起失败,请稍后重试"); } finally { setBusy(false); } }; return ( { event.preventDefault(); if (!busy) onClose(); }} onClick={(e) => { if (e.target === e.currentTarget && !busy) onClose(); }} > {socialTx("游民社区")} {socialTx("加入游民社区")} {socialTx("填写邮箱后继续")} {socialTx("邮箱")} setEmail(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && !e.nativeEvent.isComposing) void submit(); }} /> {err ? ( {err} ) : null} void submit()} > {busy ? socialTx("正在前往支付…") : socialTx("确认")} {socialTx("请填写常用邮箱,方便找回账号")} ); }
{socialTx("填写邮箱后继续")}
{err}
{socialTx("请填写常用邮箱,方便找回账号")}