Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): stop custom domain dialog bouncing to success and stacking close timers

Minit Jain78c0bf37a0f9
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 cc29a590e..477eb93b8 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 && (