-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Entering the incorrect magic code spins the 'sign-in' button continuously offline #18960
Changes from 9 commits
b66f4dc
64c878e
edd9c02
76db053
5493c7c
d068b5d
854a007
6598404
47c60f2
c631841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,9 +8,15 @@ import CONST from '../CONST'; | |||||
import Text from './Text'; | ||||||
import TextInput from './TextInput'; | ||||||
import FormHelpMessage from './FormHelpMessage'; | ||||||
import {withNetwork} from './OnyxProvider'; | ||||||
import networkPropTypes from './networkPropTypes'; | ||||||
import useOnNetworkReconnect from './hooks/useOnNetworkReconnect'; | ||||||
import * as Browser from '../libs/Browser'; | ||||||
|
||||||
const propTypes = { | ||||||
/** Information about the network */ | ||||||
network: networkPropTypes.isRequired, | ||||||
|
||||||
/** Name attribute for the input */ | ||||||
name: PropTypes.string, | ||||||
|
||||||
|
@@ -103,16 +109,22 @@ function MagicCodeInput(props) { | |||||
}, | ||||||
})); | ||||||
|
||||||
useEffect(() => { | ||||||
// Blurs the input and removes focus from the last input and, if it should submit | ||||||
// on complete, it will call the onFulfill callback. | ||||||
const validateAndSubmit = () => { | ||||||
const numbers = decomposeString(props.value); | ||||||
if (!props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== CONST.MAGIC_CODE_LENGTH) { | ||||||
if (!props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== CONST.MAGIC_CODE_LENGTH || props.network.isOffline) { | ||||||
return; | ||||||
} | ||||||
// Blurs the input and removes focus from the last input and, if it should submit | ||||||
// on complete, it will call the onFulfill callback. | ||||||
inputRefs.current[editIndex].blur(); | ||||||
setFocusedIndex(undefined); | ||||||
props.onFulfill(props.value); | ||||||
}; | ||||||
|
||||||
useOnNetworkReconnect(validateAndSubmit); | ||||||
|
||||||
useEffect(() => { | ||||||
validateAndSubmit(); | ||||||
|
||||||
// We have not added the editIndex as the dependency because we don't want to run this logic after focusing on an input to edit it after the user has completed the code. | ||||||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||||||
|
@@ -255,6 +267,10 @@ function MagicCodeInput(props) { | |||||
setEditIndex(newFocusedIndex); | ||||||
inputRefs.current[newFocusedIndex].focus(); | ||||||
} else if (keyValue === 'Enter') { | ||||||
// we shouldn also prevent user from submit here when it's offline. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, just updated, Thank you @puneetlath |
||||||
if (props.network.isOffline) { | ||||||
return; | ||||||
} | ||||||
setInput(''); | ||||||
props.onFulfill(props.value); | ||||||
} | ||||||
|
@@ -321,10 +337,12 @@ function MagicCodeInput(props) { | |||||
MagicCodeInput.propTypes = propTypes; | ||||||
MagicCodeInput.defaultProps = defaultProps; | ||||||
|
||||||
export default forwardRef((props, ref) => ( | ||||||
<MagicCodeInput | ||||||
// eslint-disable-next-line react/jsx-props-no-spreading | ||||||
{...props} | ||||||
innerRef={ref} | ||||||
/> | ||||||
)); | ||||||
export default withNetwork()( | ||||||
forwardRef((props, ref) => ( | ||||||
<MagicCodeInput | ||||||
// eslint-disable-next-line react/jsx-props-no-spreading | ||||||
{...props} | ||||||
innerRef={ref} | ||||||
/> | ||||||
)), | ||||||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, just dropping a note that this PR might have missed a case, causing the bug - "Incorrect magic code" error if click "Go back" in 2FA input page
Explaination of the problem - #19712 (comment)