This commit is contained in:
eric
2026-03-12 19:54:58 -05:00
parent 14bbd3b306
commit f66859c032
31 changed files with 1132 additions and 312 deletions

View File

@@ -15,9 +15,11 @@ interface JoinModalProps {
isOpen: boolean;
onClose: () => void;
initialEmail?: string;
/** 仅登录(已有 VIP 用户验证密码后直接登录,不跳转支付) */
vipOnly?: boolean;
}
export default function JoinModal({ isOpen, onClose, initialEmail = "" }: JoinModalProps) {
export default function JoinModal({ isOpen, onClose, initialEmail = "", vipOnly = false }: JoinModalProps) {
const locale = useLocale();
const [email, setEmail] = useState(initialEmail);
const [password, setPassword] = useState("");
@@ -34,6 +36,7 @@ export default function JoinModal({ isOpen, onClose, initialEmail = "" }: JoinMo
const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
if (loading) return;
const em = email.trim();
if (!em) {
setError(locale === "zh" ? "请输入邮箱" : "Please enter your email");
@@ -52,12 +55,21 @@ export default function JoinModal({ isOpen, onClose, initialEmail = "" }: JoinMo
if (!res.ok || !data?.ok) {
throw new Error(data?.error || (locale === "zh" ? "操作失败" : "Operation failed"));
}
const { pbSaveAuth } = await import("@/app/lib/pocketbase");
pbSaveAuth(data.token, data.record);
await fetch("/api/auth/sync-session", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: data.token, record: data.record }),
credentials: "include",
});
if (typeof window !== "undefined") {
window.dispatchEvent(new CustomEvent("auth:updated"));
}
if (vipOnly) {
onClose();
return;
}
const returnUrl = typeof window !== "undefined" ? `${window.location.origin}/${locale}/join/paid` : "/zh/join/paid";
const env: PayEnv = typeof window !== "undefined" ? (navigator.userAgent.includes("MicroMessenger") ? "wechat" : "pc") : "pc";
const channel: PayChannel = mustUseWxPay(env) ? "wxpay" : getRecommendedChannel(env);
@@ -96,11 +108,8 @@ export default function JoinModal({ isOpen, onClose, initialEmail = "" }: JoinMo
</button>
<h2 className="text-xl font-bold text-gray-800 dark:text-gray-100">
{locale === "zh" ? "加入游牧中国" : "Join Nomad China"}
{vipOnly ? (locale === "zh" ? "验证密码登录" : "Verify password to login") : (locale === "zh" ? "加入游牧中国" : "Join Nomad China")}
</h2>
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">
{locale === "zh" ? "新用户将自动注册,老用户请输入密码" : "New users auto-register; existing users enter password"}
</p>
<form onSubmit={handleSubmit} className="mt-6 space-y-4">
<div>
@@ -118,13 +127,13 @@ export default function JoinModal({ isOpen, onClose, initialEmail = "" }: JoinMo
</div>
<div>
<label className="mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300">
{locale === "zh" ? "密码(老用户必填)" : "Password (required for existing users)"}
{locale === "zh" ? "密码" : "Password"}
</label>
<input
type="password"
value={password}
onChange={(e) => { setPassword(e.target.value); setError(null); }}
placeholder={locale === "zh" ? "新用户可留空" : "Leave empty for new users"}
placeholder={locale === "zh" ? "请输入密码" : "Enter your password"}
className="w-full rounded-lg border border-gray-200 px-4 py-2.5 text-gray-800 placeholder-gray-400 focus:border-[#ff4d4f] focus:outline-none focus:ring-1 focus:ring-[#ff4d4f] dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100"
/>
</div>
@@ -136,13 +145,9 @@ export default function JoinModal({ isOpen, onClose, initialEmail = "" }: JoinMo
disabled={loading}
className="w-full rounded-lg bg-[#ff4d4f] py-3 font-semibold text-white transition-colors hover:bg-[#ff3333] disabled:opacity-70"
>
{loading ? (locale === "zh" ? "处理中…" : "Processing…") : (locale === "zh" ? "加入游牧中国 →" : "Join Nomad China →")}
{loading ? (locale === "zh" ? "处理中…" : "Processing…") : vipOnly ? (locale === "zh" ? "登录" : "Login") : (locale === "zh" ? "加入游牧中国 →" : "Join Nomad China →")}
</button>
</form>
<p className="text-xs text-gray-400 dark:text-gray-500 text-center mt-3">
{locale === "zh" ? "新用户将自动注册,支付成功后需修改默认密码" : "New users auto-register; change default password after payment"}
</p>
</div>
</div>
</div>