mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-19 07:55:25 +02:00
fixed FormikAutoLockNavigation.tsx
This commit is contained in:
parent
2cb17e5550
commit
fd27a8ca74
@ -1,27 +1,29 @@
|
|||||||
import {FormikContextType} from "formik"
|
import {FormikContextType} from "formik"
|
||||||
import {useContext} from "react"
|
import {useContext} from "react"
|
||||||
import {useDeepCompareEffect} from "react-use"
|
import {useShallowCompareEffect} from "react-use"
|
||||||
import deepEqual from "deep-equal"
|
import deepEqual from "deep-equal"
|
||||||
|
|
||||||
import LockNavigationContext from "./LockNavigationContext"
|
import LockNavigationContext from "./LockNavigationContext"
|
||||||
|
|
||||||
export interface LockNavigationContextProviderProps {
|
export interface LockNavigationContextProviderProps {
|
||||||
formik: FormikContextType<any>
|
formik: FormikContextType<any>
|
||||||
|
|
||||||
|
active?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FormikAutoLockNavigation({
|
export default function FormikAutoLockNavigation({
|
||||||
formik,
|
formik,
|
||||||
|
active = true,
|
||||||
}: LockNavigationContextProviderProps): null {
|
}: LockNavigationContextProviderProps): null {
|
||||||
const {lock, release} = useContext(LockNavigationContext)
|
const {lock, release} = useContext(LockNavigationContext)
|
||||||
|
|
||||||
// TODO: Not working yet
|
useShallowCompareEffect(() => {
|
||||||
useDeepCompareEffect(() => {
|
if (!deepEqual(formik.values, formik.initialValues) && active) {
|
||||||
if (!deepEqual(formik.values, formik.initialValues)) {
|
|
||||||
lock()
|
lock()
|
||||||
} else {
|
} else {
|
||||||
release()
|
release()
|
||||||
}
|
}
|
||||||
}, [lock, release, formik.values, formik.initialValues])
|
}, [lock, release, formik.values, formik.initialValues, formik.isSubmitting, active])
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ export default function AliasNotesForm({id, notes, onChanged}: AliasNotesFormPro
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</form>
|
</form>
|
||||||
<FormikAutoLockNavigation formik={formik} />
|
<FormikAutoLockNavigation active={isInEditMode} formik={formik} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user