From 4185dc561848710eda7ab3a188e60f77b4502698 Mon Sep 17 00:00:00 2001 From: Srinivasa IK Varanasi <79159341+MrVSiK@users.noreply.github.com> Date: Sat, 7 Oct 2023 06:31:46 +0530 Subject: [PATCH] fix: Refreshing wizard causes loss of progress (#791) Added an eventListener to listen for beforeunload event. Pops up a confirmation dialog box Co-authored-by: bautistaaa --- .../src/app/[locale]/wizard/_components/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/web/src/app/[locale]/wizard/_components/index.tsx b/apps/web/src/app/[locale]/wizard/_components/index.tsx index 87dfc5bcd..305645071 100644 --- a/apps/web/src/app/[locale]/wizard/_components/index.tsx +++ b/apps/web/src/app/[locale]/wizard/_components/index.tsx @@ -107,6 +107,18 @@ export function Wizard() { useEffect(() => { setRendered(true); + + const handleBeforeUnload: EventListenerOrEventListenerObject = (event) => { + event.preventDefault(); + event.returnValue = false; + }; + + window.addEventListener('beforeunload', handleBeforeUnload, { capture: true }); + + return () => { + // Clean up the event listener when the component unmounts + window.removeEventListener('beforeunload', handleBeforeUnload); + }; }, []); const handleNextClick = async () => {