create safe form validation logic fixes
This commit is contained in:
parent
57cc985730
commit
2d998b2f24
|
@ -45,6 +45,9 @@ const ScanQRModal = ({
|
|||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
// this fires only when the hasWebcam changes to false (null > false (user doesn't have webcam)
|
||||
// , true > false (user switched from webcam to file upload))
|
||||
// Doesn't fire on re-render
|
||||
if (hasWebcam === false) {
|
||||
openImageDialog()
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ export const calculateValuesAfterRemoving = (index: number, notRemovedOwners: nu
|
|||
initialValues[FIELD_CONFIRMATIONS] = numOwnersAfterRemoving.toString()
|
||||
}
|
||||
|
||||
delete initialValues[getOwnerNameBy(numOwnersAfterRemoving)]
|
||||
delete initialValues[getOwnerAddressBy(numOwnersAfterRemoving)]
|
||||
delete initialValues[getOwnerNameBy(index)]
|
||||
delete initialValues[getOwnerAddressBy(index)]
|
||||
|
||||
return initialValues
|
||||
}
|
||||
|
@ -87,8 +87,15 @@ const SafeOwners = (props: Props) => {
|
|||
form.reset()
|
||||
} else {
|
||||
const initialValues = calculateValuesAfterRemoving(index, numOwners, values)
|
||||
|
||||
if (Object.keys(initialValues).length === 4) {
|
||||
// this means that the form is back to its inital state
|
||||
// and if they're equal it won't update the form
|
||||
form.reset()
|
||||
} else {
|
||||
updateInitialProps(initialValues)
|
||||
}
|
||||
}
|
||||
|
||||
setNumOwners(numOwners - 1)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ export const getOwnerAddressBy = (index: number) => `owner${index}Address`
|
|||
export const getNumOwnersFrom = (values: Object) => {
|
||||
const accounts = Object.keys(values)
|
||||
.sort()
|
||||
.filter(key => /^owner\d+Name$/.test(key))
|
||||
.filter(key => /^owner\d+Address$/.test(key) && !!values[key])
|
||||
|
||||
return accounts.length
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue