From 7333e99e25d4bcfe2aa23d03087412ac61ecbd2f Mon Sep 17 00:00:00 2001 From: Juan Carlos Farah Date: Fri, 12 Apr 2024 15:26:24 +0200 Subject: [PATCH] fix: attempt to make warning work on mobile --- src/modules/interaction/ParticipantInteraction.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/modules/interaction/ParticipantInteraction.tsx b/src/modules/interaction/ParticipantInteraction.tsx index f2a9fb0..50224ef 100644 --- a/src/modules/interaction/ParticipantInteraction.tsx +++ b/src/modules/interaction/ParticipantInteraction.tsx @@ -122,14 +122,21 @@ const ParticipantInteraction = (): ReactElement => { useState(defaultInteraction); useEffect(() => { - const handleBeforeUnload = (event: BeforeUnloadEvent): void => { + const handleBeforeUnload = (event: BeforeUnloadEvent): string => { if (!interaction.completed) { // Perform actions before the component unloads event.preventDefault(); - // eslint-disable-next-line no-alert,no-restricted-globals - confirm('Confirm refresh'); + // Chrome requires returnValue to be set + // Prompt the user before leaving + const confirmationMessage = 'Are you sure you want to leave?'; + + // Chrome requires returnValue to be set + // eslint-disable-next-line no-param-reassign + event.returnValue = confirmationMessage; // For Chrome + return confirmationMessage; // For standard browsers } + return ''; }; window.addEventListener('beforeunload', handleBeforeUnload); return () => {