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);
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 {

View File

@ -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 (