From cc4ce9b4456249d74ba746ce4f26d8b6c63cce23 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 4 Jul 2023 10:30:26 +0700 Subject: [PATCH 1/2] fix: 20848 enable 2fa button in verify page --- .../BaseTwoFactorAuthForm.js | 21 +++++++++++++++-- .../TwoFactorAuthForm/index.android.js | 23 +++++++++++++++++-- .../TwoFactorAuth/TwoFactorAuthForm/index.js | 23 +++++++++++++++++-- .../Security/TwoFactorAuth/VerifyPage.js | 8 +++++-- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/BaseTwoFactorAuthForm.js b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/BaseTwoFactorAuthForm.js index ca78219178ef..3b9395661c6d 100644 --- a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/BaseTwoFactorAuthForm.js +++ b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/BaseTwoFactorAuthForm.js @@ -1,4 +1,4 @@ -import React, {useCallback, useState} from 'react'; +import React, {useCallback, useState, forwardRef, useImperativeHandle} from 'react'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import MagicCodeInput from '../../../../../components/MagicCodeInput'; @@ -31,6 +31,7 @@ const defaultProps = { function BaseTwoFactorAuthForm(props) { const [formError, setFormError] = useState({}); const [twoFactorAuthCode, setTwoFactorAuthCode] = useState(''); + const inputRef = React.useRef(null); /** * Handle text input and clear formError upon text change @@ -53,6 +54,7 @@ function BaseTwoFactorAuthForm(props) { * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { + inputRef.current.blur(); if (!twoFactorAuthCode.trim()) { setFormError({twoFactorAuthCode: 'twoFactorAuthForm.error.pleaseFillTwoFactorAuth'}); return; @@ -67,6 +69,12 @@ function BaseTwoFactorAuthForm(props) { Session.validateTwoFactorAuth(twoFactorAuthCode); }, [twoFactorAuthCode]); + useImperativeHandle(props.innerRef, () => ({ + validateAndSubmitForm() { + validateAndSubmitForm(); + }, + })); + return ( ); } @@ -90,4 +99,12 @@ export default compose( withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, }), -)(BaseTwoFactorAuthForm); +)( + forwardRef((props, ref) => ( + + )), +); diff --git a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.android.js b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.android.js index ea0d5e257e2f..ba7bb2186aa6 100644 --- a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.android.js +++ b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.android.js @@ -1,10 +1,29 @@ import React from 'react'; +import PropTypes from 'prop-types'; import BaseTwoFactorAuthForm from './BaseTwoFactorAuthForm'; -function TwoFactorAuthForm() { - return ; +const propTypes = { + /** + * A ref to forward to the Pressable + */ + innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), +}; + +const defaultProps = { + innerRef: () => {}, +}; + +function TwoFactorAuthForm(props) { + return ( + + ); } +TwoFactorAuthForm.propTypes = propTypes; +TwoFactorAuthForm.defaultProps = defaultProps; TwoFactorAuthForm.displayName = 'TwoFactorAuthForm'; export default TwoFactorAuthForm; diff --git a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.js b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.js index c52e65facd6d..171322ecb32d 100644 --- a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.js +++ b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/index.js @@ -1,10 +1,29 @@ import React from 'react'; +import PropTypes from 'prop-types'; import BaseTwoFactorAuthForm from './BaseTwoFactorAuthForm'; -function TwoFactorAuthForm() { - return ; +const propTypes = { + /** + * A ref to forward to the Pressable + */ + innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), +}; + +const defaultProps = { + innerRef: () => {}, +}; + +function TwoFactorAuthForm(props) { + return ( + + ); } +TwoFactorAuthForm.propTypes = propTypes; +TwoFactorAuthForm.defaultProps = defaultProps; TwoFactorAuthForm.displayName = 'TwoFactorAuthForm'; export default TwoFactorAuthForm; diff --git a/src/pages/settings/Security/TwoFactorAuth/VerifyPage.js b/src/pages/settings/Security/TwoFactorAuth/VerifyPage.js index 90765b45caa2..d487d7cc027f 100644 --- a/src/pages/settings/Security/TwoFactorAuth/VerifyPage.js +++ b/src/pages/settings/Security/TwoFactorAuth/VerifyPage.js @@ -55,6 +55,8 @@ const defaultProps = { }; function VerifyPage(props) { + const formRef = React.useRef(null); + useEffect(() => { Session.clearAccountMessages(); }, []); @@ -139,15 +141,17 @@ function VerifyPage(props) { {props.translate('twoFactorAuth.enterCode')} - +