diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx index cc29a590e74..477eb93b886 100644 --- a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx +++ b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx @@ -267,6 +267,22 @@ const CustomDomainDialog = ({ onClose(); }, [handleReset, onClose]); + const handleCloseRef = useRef(handleClose); + handleCloseRef.current = handleClose; + + useEffect(() => { + if (isVerified) { + dispatch({ type: "GO_TO_STEP", payload: 2 }); + } + }, [isVerified]); + + useEffect(() => { + if (stepState.currentIndex !== 2) return; + // Read handleClose via a ref: the parent passes an inline onClose, so depending on it would restart the countdown on every parent render. + const timer = setTimeout(() => handleCloseRef.current(), 8000); + return () => clearTimeout(timer); + }, [stepState.currentIndex]); + const checkVerification = useCallback( (showToasts = true) => { if ( @@ -343,17 +359,6 @@ const CustomDomainDialog = ({ }); }; - useEffect(() => { - //if current step is success, close dialog in 8 seconds - if (stepState.currentIndex === 2) { - setTimeout(() => { - handleClose(); - }, 8000); - } else if (isVerified) { - handleNext(); - } - }, [isVerified, stepState.currentIndex, handleClose, handleNext]); - return ( <> {stepState.currentIndex === 2 && (