From 4d17066939bc1d3922d6f8e535812e05083fb896 Mon Sep 17 00:00:00 2001 From: Amirhossein Khalili Date: Thu, 1 Oct 2026 13:35:22 +0330 Subject: [PATCH] fix(events): bound registration status loading --- src/lib/api.ts | 24 ++++++++++++++++++++---- src/views/EventRegistrationHub.tsx | 3 +++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lib/api.ts b/src/lib/api.ts index 16cd1d6..8258911 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1087,10 +1087,26 @@ class ApiClient { if (identifiers.registration_id) query.set("registration_id", identifiers.registration_id); if (identifiers.payment_id) query.set("payment_id", String(identifiers.payment_id)); const suffix = query.size ? `?${query.toString()}` : ""; - return this.request( - `/api/events/${encodeURIComponent(eventSlug)}/registration/status${suffix}`, - { method: "GET" }, - ); + const controller = new AbortController(); + const timeout = window.setTimeout(() => controller.abort(), 15_000); + try { + return await Promise.race([ + this.request( + `/api/events/${encodeURIComponent(eventSlug)}/registration/status${suffix}`, + { method: "GET", signal: controller.signal }, + ), + new Promise((_, reject) => { + controller.signal.addEventListener("abort", () => reject(new DOMException("Timed out", "AbortError")), { once: true }); + }), + ]); + } catch (error) { + if (error instanceof DOMException && error.name === "AbortError") { + throw new Error("دریافت وضعیت ثبت‌نام بیش از حد طول کشید. دوباره تلاش کنید."); + } + throw error; + } finally { + window.clearTimeout(timeout); + } } // ============= Payment Endpoints ============= diff --git a/src/views/EventRegistrationHub.tsx b/src/views/EventRegistrationHub.tsx index 3e6d8ad..0391f66 100644 --- a/src/views/EventRegistrationHub.tsx +++ b/src/views/EventRegistrationHub.tsx @@ -371,6 +371,9 @@ export default function EventRegistrationHub({ slug, registrationId, paymentId } }; const primaryAction: OutcomeAction | undefined = (() => { + if (loadState === "error") { + return { label: "بررسی دوباره", onClick: refreshNow, disabled: refreshing }; + } if (!data || !state) return undefined; if (state === "ready" && data.can_register) { return data.event.price > 0