Skip to content

Commit

Permalink
Merge pull request #33401 from sourcecodedeveloper/magicCodeSentTwice
Browse files Browse the repository at this point in the history
resolve magic code sent twice
  • Loading branch information
rlinoz authored Dec 26, 2023
2 parents 64a88e4 + bebd1c4 commit 2b58e1c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pages/signin/LoginForm/BaseLoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function LoginForm(props) {
const prevIsVisible = usePrevious(props.isVisible);
const firstBlurred = useRef(false);
const isFocused = useIsFocused();
const isLoading = useRef(false);

const {translate} = props;

Expand Down Expand Up @@ -165,9 +166,10 @@ function LoginForm(props) {
* Check that all the form fields are valid, then trigger the submit callback
*/
const validateAndSubmitForm = useCallback(() => {
if (props.network.isOffline || props.account.isLoading) {
if (props.network.isOffline || props.account.isLoading || isLoading.current) {
return;
}
isLoading.current = true;

// If account was closed and have success message in Onyx, we clear it here
if (!_.isEmpty(props.closeAccount.success)) {
Expand All @@ -181,6 +183,7 @@ function LoginForm(props) {
}

if (!validate(login)) {
isLoading.current = false;
return;
}

Expand Down Expand Up @@ -219,6 +222,13 @@ function LoginForm(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps -- we just want to call this function when component is mounted
}, []);

useEffect(() => {
if (props.account.isLoading !== false) {
return;
}
isLoading.current = false;
}, [props.account.isLoading]);

useEffect(() => {
if (props.blurOnSubmit) {
input.current.blur();
Expand Down

0 comments on commit 2b58e1c

Please sign in to comment.