's'
This commit is contained in:
@@ -2,16 +2,11 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import Link from "next/link";
|
||||
import { tryCompleteOrder, applyCompleteSuccess } from "@/app/lib/complete-order";
|
||||
import { clearPendingOrder } from "@/app/hooks/useCompleteOrderPolling";
|
||||
|
||||
const WECHAT_STORAGE_KEY = "salon_join_wechat";
|
||||
|
||||
function clearPendingOrder(): void {
|
||||
try {
|
||||
localStorage.removeItem("join_pay_order");
|
||||
} catch {}
|
||||
document.cookie = "join_pay_order=; path=/; max-age=0";
|
||||
}
|
||||
|
||||
export default function JoinPaidPage() {
|
||||
const [completeStatus, setCompleteStatus] = useState<"pending" | "success" | "error">("pending");
|
||||
const [errorDetail, setErrorDetail] = useState<string | null>(null);
|
||||
@@ -21,31 +16,6 @@ export default function JoinPaidPage() {
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
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" },
|
||||
body: JSON.stringify({ order_id: orderId }),
|
||||
credentials: "include",
|
||||
});
|
||||
const d = await r.json();
|
||||
if (!d?.ok) return { ok: false, error: d?.error || d?.detail || `HTTP ${r.status}` };
|
||||
|
||||
if (d?.token && d?.record) {
|
||||
await fetch("/api/auth/sync-session", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: d.token, record: d.record }),
|
||||
credentials: "include",
|
||||
});
|
||||
const { pbSaveAuth } = await import("@/app/lib/pocketbase");
|
||||
pbSaveAuth(d.token, d.record);
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent("auth:updated"));
|
||||
window.dispatchEvent(new CustomEvent("vip:updated"));
|
||||
return { ok: true, record: d?.record };
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
const urlOrderId = typeof window !== "undefined"
|
||||
? new URLSearchParams(window.location.search).get("order_id") || ""
|
||||
@@ -68,13 +38,18 @@ export default function JoinPaidPage() {
|
||||
}
|
||||
|
||||
const maxClientRetries = 5;
|
||||
const retryDelays = [2000, 3000, 4000, 5000, 6000];
|
||||
const retryDelays = [800, 1500, 2500, 4000, 6000];
|
||||
let lastError = "";
|
||||
for (let i = 0; i <= maxClientRetries; i++) {
|
||||
if (cancelled) return;
|
||||
try {
|
||||
const result = await tryComplete(orderId);
|
||||
const result = await tryCompleteOrder(orderId);
|
||||
if (result.ok) {
|
||||
if (result.token && result.record) {
|
||||
applyCompleteSuccess({ token: result.token, record: result.record });
|
||||
} else if (result.record) {
|
||||
applyCompleteSuccess({ token: "", record: result.record });
|
||||
}
|
||||
clearPendingOrder();
|
||||
if (!cancelled) {
|
||||
setCompleteStatus("success");
|
||||
|
||||
Reference in New Issue
Block a user