From d60bbfe4c3f072274ce0f106209fbd427a1da4e7 Mon Sep 17 00:00:00 2001 From: deepvasoya Date: Mon, 2 Jun 2025 14:32:25 +0530 Subject: [PATCH] feat: invoice waiting page --- src/views/Signup/YourDetailsForm.jsx | 12 +++++------ src/views/WaitingPage/index.jsx | 32 ++++++++++------------------ 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/views/Signup/YourDetailsForm.jsx b/src/views/Signup/YourDetailsForm.jsx index ee2f34b..30b0f46 100644 --- a/src/views/Signup/YourDetailsForm.jsx +++ b/src/views/Signup/YourDetailsForm.jsx @@ -398,13 +398,13 @@ function YourDetailsForm() { pushNotification(response?.data?.message, NOTIFICATION.SUCCESS); localStorage.setItem("temp_signup_token", response?.data?.data?.token); // open new page for stripe payment from url - window.open(response?.data?.data?.url, "_blank", "noopener,noreferrer"); - // if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') { - // // Fallback in case popup is blocked - // window.location.href = response?.data?.data; - // } + let newWindow = window.open(response?.data?.data?.url, "_blank", "noopener,noreferrer"); + if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') { + // Fallback in case popup is blocked + window.location.href = response?.data?.data?.url; + } dispatch(resetFormData()); - navigate("/"); + navigate("/auth/waiting"); } catch (error) { console.error("Error signing up:", error); } finally { diff --git a/src/views/WaitingPage/index.jsx b/src/views/WaitingPage/index.jsx index 7e85f66..7bf1ee7 100644 --- a/src/views/WaitingPage/index.jsx +++ b/src/views/WaitingPage/index.jsx @@ -38,9 +38,10 @@ const PaymentSuccessPage = () => { const timerRef = useRef(null); const isPollingActiveRef = useRef(false); - const checkPaymentStatus = async () => { + const checkPaymentStatus = async (authToken = null) => { try { - if (!token || !isPollingActiveRef.current) { + const tokenToUse = authToken || token; + if (!tokenToUse || !isPollingActiveRef.current) { return; } @@ -48,7 +49,7 @@ const PaymentSuccessPage = () => { method: "GET", headers: { "Content-Type": "application/json", - Authorization: `Bearer ${token}`, + Authorization: `Bearer ${tokenToUse}`, }, }); @@ -70,13 +71,14 @@ const PaymentSuccessPage = () => { setInvoiceUrl(data.data); } else if (isPollingActiveRef.current) { // Still processing, check again in 10 seconds - pollingRef.current = setTimeout(() => checkPaymentStatus(), 10000); + pollingRef.current = setTimeout(() => checkPaymentStatus(tokenToUse), 10000); } } catch (error) { console.error("Error checking payment status:", error); if (isPollingActiveRef.current) { // Retry after 10 seconds on error - pollingRef.current = setTimeout(() => checkPaymentStatus(), 10000); + const tokenToUse = authToken || token; + pollingRef.current = setTimeout(() => checkPaymentStatus(tokenToUse), 10000); } } }; @@ -132,7 +134,7 @@ const PaymentSuccessPage = () => { setTimeElapsed(0); isPollingActiveRef.current = true; startTimer(); - checkPaymentStatus(); + checkPaymentStatus(token); }; const formatTime = (seconds) => { @@ -152,14 +154,8 @@ const PaymentSuccessPage = () => { isPollingActiveRef.current = true; startTimer(); - // Start checking payment status once token is set - const initializeChecking = async () => { - if (storedToken) { - checkPaymentStatus(); - } - }; - - initializeChecking(); + // Start checking payment status immediately with the stored token + checkPaymentStatus(storedToken); // Cleanup function return () => { @@ -167,13 +163,7 @@ const PaymentSuccessPage = () => { }; }, []); // Remove token from dependency array to avoid infinite loop - // Separate useEffect for when token changes - useEffect(() => { - if (token && status === "processing" && !isPollingActiveRef.current) { - isPollingActiveRef.current = true; - checkPaymentStatus(); - } - }, [token]); + // Remove the separate useEffect for token changes since we handle it in the main useEffect if (status === "processing") { return (