UX optimization

This commit is contained in:
Jakob Wennberg
2026-02-23 19:05:16 +01:00
parent c510bfab9e
commit 431f385b4b
23 changed files with 937 additions and 58 deletions
+22
View File
@@ -0,0 +1,22 @@
'use client'
import { useEffect } from 'react'
/**
* Attaches a `beforeunload` event listener when the form has unsaved changes.
* This guards against browser close, tab close, and page refresh.
*
* Does NOT guard in-app Next.js navigation (App Router has no supported mechanism).
*/
export function useUnsavedChanges(isDirty: boolean) {
useEffect(() => {
if (!isDirty) return
const handler = (e: BeforeUnloadEvent) => {
e.preventDefault()
}
window.addEventListener('beforeunload', handler)
return () => window.removeEventListener('beforeunload', handler)
}, [isDirty])
}