Skip to content

Commit

Permalink
Merge pull request #25781 from Expensify/revert-23995-fix/issue-21958
Browse files Browse the repository at this point in the history
Revert "fix: revalidate upon input and refocus if error occurs"
  • Loading branch information
roryabraham committed Aug 23, 2023
2 parents 15d1511 + a7bacb9 commit 43c6f11
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions src/components/MagicCodeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,21 @@ function MagicCodeInput(props) {
},
}));

/**
* Validate the entered code and submit
*
* @param {String} value
*/
const validateAndSubmit = (value) => {
const numbers = decomposeString(value, props.maxLength);
const validateAndSubmit = () => {
const numbers = decomposeString(props.value, props.maxLength);
if (!props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || 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.
blurMagicCodeInput();
props.onFulfill(value);
props.onFulfill(props.value);
};

useNetwork({onReconnect: () => validateAndSubmit(props.value)});
useNetwork({onReconnect: validateAndSubmit});

useEffect(() => {
if (!props.hasError) {
return;
}

// Focus the last input if an error occurred to allow for corrections
inputRefs.current[props.maxLength - 1].focus();
}, [props.hasError, props.maxLength]);

useEffect(() => {
validateAndSubmit(props.value);
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.
Expand Down Expand Up @@ -193,11 +179,6 @@ function MagicCodeInput(props) {

const finalInput = composeToString(numbers);
props.onChangeText(finalInput);

// If the same number is pressed, we cannot depend on props.value in useEffect for re-submitting
if (props.value === finalInput) {
validateAndSubmit(finalInput);
}
};

/**
Expand Down

0 comments on commit 43c6f11

Please sign in to comment.