chore: use monorepo organization
This commit is contained in:
parent
deaf7d6ecc
commit
a687827f7e
1099 changed files with 8184 additions and 11535 deletions
28
packages/admin-ui/src/components/PromptWhenDirty.jsx
Normal file
28
packages/admin-ui/src/components/PromptWhenDirty.jsx
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { useFormikContext } from 'formik'
|
||||
import React, { useEffect } from 'react'
|
||||
import { Prompt } from 'react-router-dom'
|
||||
|
||||
const PROMPT_DEFAULT_MESSAGE =
|
||||
'You have unsaved changes on this page. Are you sure you want to leave?'
|
||||
|
||||
const PromptWhenDirty = ({ message = PROMPT_DEFAULT_MESSAGE }) => {
|
||||
const formik = useFormikContext()
|
||||
|
||||
const hasChanges = formik.dirty && formik.submitCount === 0
|
||||
|
||||
useEffect(() => {
|
||||
if (hasChanges) {
|
||||
window.onbeforeunload = confirmExit
|
||||
} else {
|
||||
window.onbeforeunload = undefined
|
||||
}
|
||||
}, [hasChanges])
|
||||
|
||||
const confirmExit = () => {
|
||||
return PROMPT_DEFAULT_MESSAGE
|
||||
}
|
||||
|
||||
return <Prompt when={hasChanges} message={message} />
|
||||
}
|
||||
|
||||
export default PromptWhenDirty
|
||||
Loading…
Add table
Add a link
Reference in a new issue