feat: invoice waiting page

This commit is contained in:
deepvasoya 2025-06-02 14:32:25 +05:30
parent 344d5792ed
commit d60bbfe4c3
2 changed files with 17 additions and 27 deletions

View File

@ -398,13 +398,13 @@ function YourDetailsForm() {
pushNotification(response?.data?.message, NOTIFICATION.SUCCESS); pushNotification(response?.data?.message, NOTIFICATION.SUCCESS);
localStorage.setItem("temp_signup_token", response?.data?.data?.token); localStorage.setItem("temp_signup_token", response?.data?.data?.token);
// open new page for stripe payment from url // open new page for stripe payment from url
window.open(response?.data?.data?.url, "_blank", "noopener,noreferrer"); let newWindow = window.open(response?.data?.data?.url, "_blank", "noopener,noreferrer");
// if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') { if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') {
// // Fallback in case popup is blocked // Fallback in case popup is blocked
// window.location.href = response?.data?.data; window.location.href = response?.data?.data?.url;
// } }
dispatch(resetFormData()); dispatch(resetFormData());
navigate("/"); navigate("/auth/waiting");
} catch (error) { } catch (error) {
console.error("Error signing up:", error); console.error("Error signing up:", error);
} finally { } finally {

View File

@ -38,9 +38,10 @@ const PaymentSuccessPage = () => {
const timerRef = useRef(null); const timerRef = useRef(null);
const isPollingActiveRef = useRef(false); const isPollingActiveRef = useRef(false);
const checkPaymentStatus = async () => { const checkPaymentStatus = async (authToken = null) => {
try { try {
if (!token || !isPollingActiveRef.current) { const tokenToUse = authToken || token;
if (!tokenToUse || !isPollingActiveRef.current) {
return; return;
} }
@ -48,7 +49,7 @@ const PaymentSuccessPage = () => {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${token}`, Authorization: `Bearer ${tokenToUse}`,
}, },
}); });
@ -70,13 +71,14 @@ const PaymentSuccessPage = () => {
setInvoiceUrl(data.data); setInvoiceUrl(data.data);
} else if (isPollingActiveRef.current) { } else if (isPollingActiveRef.current) {
// Still processing, check again in 10 seconds // Still processing, check again in 10 seconds
pollingRef.current = setTimeout(() => checkPaymentStatus(), 10000); pollingRef.current = setTimeout(() => checkPaymentStatus(tokenToUse), 10000);
} }
} catch (error) { } catch (error) {
console.error("Error checking payment status:", error); console.error("Error checking payment status:", error);
if (isPollingActiveRef.current) { if (isPollingActiveRef.current) {
// Retry after 10 seconds on error // 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); setTimeElapsed(0);
isPollingActiveRef.current = true; isPollingActiveRef.current = true;
startTimer(); startTimer();
checkPaymentStatus(); checkPaymentStatus(token);
}; };
const formatTime = (seconds) => { const formatTime = (seconds) => {
@ -152,14 +154,8 @@ const PaymentSuccessPage = () => {
isPollingActiveRef.current = true; isPollingActiveRef.current = true;
startTimer(); startTimer();
// Start checking payment status once token is set // Start checking payment status immediately with the stored token
const initializeChecking = async () => { checkPaymentStatus(storedToken);
if (storedToken) {
checkPaymentStatus();
}
};
initializeChecking();
// Cleanup function // Cleanup function
return () => { return () => {
@ -167,13 +163,7 @@ const PaymentSuccessPage = () => {
}; };
}, []); // Remove token from dependency array to avoid infinite loop }, []); // Remove token from dependency array to avoid infinite loop
// Separate useEffect for when token changes // Remove the separate useEffect for token changes since we handle it in the main useEffect
useEffect(() => {
if (token && status === "processing" && !isPollingActiveRef.current) {
isPollingActiveRef.current = true;
checkPaymentStatus();
}
}, [token]);
if (status === "processing") { if (status === "processing") {
return ( return (