This commit is contained in:
eric
2026-03-16 09:32:35 -05:00
parent c54c236d1b
commit 14b0cd2429
21 changed files with 1058 additions and 706 deletions

View File

@@ -3,6 +3,8 @@
import { useState, useEffect } from "react";
import Link from "next/link";
const WECHAT_STORAGE_KEY = "salon_join_wechat";
function clearPendingOrder(): void {
try {
localStorage.removeItem("join_pay_order");
@@ -14,11 +16,12 @@ export default function JoinPaidPage() {
const [completeStatus, setCompleteStatus] = useState<"pending" | "success" | "error">("pending");
const [errorDetail, setErrorDetail] = useState<string | null>(null);
const [countdown, setCountdown] = useState<number | null>(null);
const [wechatId, setWechatId] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
const tryComplete = async (orderId: string): Promise<{ ok: boolean; error?: string }> => {
const tryComplete = async (orderId: string): Promise<{ ok: boolean; error?: string; record?: { wechatId?: string } }> => {
const r = await fetch("/api/salon/complete-order", {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -40,7 +43,7 @@ export default function JoinPaidPage() {
}
window.dispatchEvent(new CustomEvent("auth:updated"));
window.dispatchEvent(new CustomEvent("vip:updated"));
return { ok: true };
return { ok: true, record: d?.record };
};
const run = async () => {
@@ -73,7 +76,10 @@ export default function JoinPaidPage() {
const result = await tryComplete(orderId);
if (result.ok) {
clearPendingOrder();
if (!cancelled) setCompleteStatus("success");
if (!cancelled) {
setCompleteStatus("success");
if (result.record?.wechatId) setWechatId(result.record.wechatId);
}
return;
}
lastError = result.error || "unknown";
@@ -94,6 +100,15 @@ export default function JoinPaidPage() {
return () => { cancelled = true; };
}, []);
useEffect(() => {
try {
const stored = localStorage.getItem(WECHAT_STORAGE_KEY)?.trim();
if (stored) setWechatId(stored);
} catch {
/* ignore */
}
}, []);
const COUNTDOWN_SECONDS = 5;
useEffect(() => {
if (completeStatus !== "success") return;
@@ -123,12 +138,15 @@ export default function JoinPaidPage() {
<p className="mt-3 text-slate-500 dark:text-slate-400">
{completeStatus === "success"
? countdown != null
? `${countdown} 秒后跳转报名页`
? `${countdown} 秒后跳转报名成功`
: "感谢您的支持"
: completeStatus === "error"
? "请稍后刷新页面重试"
: "正在确认支付状态…"}
</p>
{wechatId && (
<p className="mt-2 text-xs text-slate-400 dark:text-slate-500 font-mono">: {wechatId}</p>
)}
{completeStatus === "error" && errorDetail && (
<p className="mt-1 text-xs text-slate-400 dark:text-slate-500">{errorDetail}</p>
)}
@@ -141,12 +159,18 @@ export default function JoinPaidPage() {
</button>
)}
<Link
href="/join?paid=1"
className="mt-8 inline-flex items-center gap-2 rounded-full bg-[#ff4d4f] px-8 py-3 font-semibold text-white transition-colors hover:bg-[#ff7a45]"
>
</Link>
{completeStatus === "pending" ? (
<span className="mt-8 inline-flex items-center gap-2 rounded-full bg-stone-200 dark:bg-stone-700 px-8 py-3 font-semibold text-stone-400 dark:text-stone-500 cursor-not-allowed">
</span>
) : (
<Link
href="/join?paid=1"
className="mt-8 inline-flex items-center gap-2 rounded-full bg-[#ff4d4f] px-8 py-3 font-semibold text-white transition-colors hover:bg-[#ff7a45]"
>
</Link>
)}
</div>
</div>
);