refactor(web): isolate research workflows and shared form utilities (CL30)
This commit is contained in:
parent
7ae6ac21c4
commit
a411f9a665
41 changed files with 859 additions and 699 deletions
17
apps/stock/web-app/src/hooks/useUnsavedWarning.ts
Normal file
17
apps/stock/web-app/src/hooks/useUnsavedWarning.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { useEffect } from 'react';
|
||||
|
||||
export function useUnsavedWarning(dirty: boolean) {
|
||||
useEffect(() => {
|
||||
if (!dirty) {
|
||||
return;
|
||||
}
|
||||
const warn = (event: BeforeUnloadEvent) => {
|
||||
event.preventDefault();
|
||||
event.returnValue = '';
|
||||
};
|
||||
window.addEventListener('beforeunload', warn);
|
||||
return () => window.removeEventListener('beforeunload', warn);
|
||||
}, [dirty]);
|
||||
}
|
||||
export const confirmDiscard = (dirty: boolean) =>
|
||||
!dirty || window.confirm('Discard unsaved changes?');
|
||||
Loading…
Add table
Add a link
Reference in a new issue