diff --git a/pkg/interface/src/logic/lib/util.js b/pkg/interface/src/logic/lib/util.js index 74eaece9c..c2aaa4b64 100644 --- a/pkg/interface/src/logic/lib/util.js +++ b/pkg/interface/src/logic/lib/util.js @@ -327,11 +327,18 @@ export function numToUd(num) { )(num.toString()) } -export function usePreventWindowUnload(shouldPreventDefault) { +export function usePreventWindowUnload(shouldPreventDefault, message = "You have unsaved changes. Are you sure you want to exit?") { React.useEffect(() => { if (!shouldPreventDefault) return; - const handleBeforeUnload = event => event.preventDefault(); + const handleBeforeUnload = event => { + event.preventDefault(); + return message; + } window.addEventListener("beforeunload", handleBeforeUnload); - return () => window.removeEventListener("beforeunload", handleBeforeUnload); + window.onbeforeunload = handleBeforeUnload; + return () => { + window.removeEventListener("beforeunload", handleBeforeUnload); + window.onbeforeunload = undefined; + } }, [shouldPreventDefault]); } \ No newline at end of file diff --git a/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx b/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx index 150a2a12b..b028f30ab 100644 --- a/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx +++ b/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx @@ -30,7 +30,7 @@ const PromptIfDirty = () => { return ( ); }; diff --git a/pkg/interface/src/views/landscape/components/GroupSettings.tsx b/pkg/interface/src/views/landscape/components/GroupSettings.tsx index be6169636..dc7d6c3ca 100644 --- a/pkg/interface/src/views/landscape/components/GroupSettings.tsx +++ b/pkg/interface/src/views/landscape/components/GroupSettings.tsx @@ -83,8 +83,11 @@ export function GroupSettings(props: GroupSettingsProps) { }; const onDelete = async () => { - await props.api.contacts.delete(association["group-path"]); - history.push("/"); + const name = association['group-path'].split('/').pop(); + if (prompt(`To confirm deleting this group, type ${name}`) === name) { + await props.api.contacts.delete(association["group-path"]); + history.push("/"); + } }; const disabled =