From 28532e794dcf3f8a8a7e0114cb1697bb11cfd347 Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 7 Sep 2023 18:48:41 +0700 Subject: [PATCH 1/3] Pass preferredLocale when sign in with google or apple id --- src/libs/actions/Session/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index aa5ff229267f..c61bf7b3005a 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -35,6 +35,12 @@ Onyx.connect({ callback: (val) => (credentials = val || {}), }); +let preferredLocale; +Onyx.connect({ + key: ONYXKEYS.NVP_PREFERRED_LOCALE, + callback: (val) => (preferredLocale = val), +}); + /** * Clears the Onyx store and redirects user to the sign in page */ @@ -244,7 +250,7 @@ function beginSignIn(login) { */ function beginAppleSignIn(idToken) { const {optimisticData, successData, failureData} = signInAttemptState(); - API.write('SignInWithApple', {idToken}, {optimisticData, successData, failureData}); + API.write('SignInWithApple', {idToken, preferredLocale}, {optimisticData, successData, failureData}); } /** @@ -255,7 +261,7 @@ function beginAppleSignIn(idToken) { */ function beginGoogleSignIn(token) { const {optimisticData, successData, failureData} = signInAttemptState(); - API.write('SignInWithGoogle', {token}, {optimisticData, successData, failureData}); + API.write('SignInWithGoogle', {token, preferredLocale}, {optimisticData, successData, failureData}); } /** From 5ad1310ce0d6bd2e0a32e807f3687e3015dff859 Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 7 Sep 2023 23:01:14 +0700 Subject: [PATCH 2/3] Fix linter --- src/libs/actions/Session/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index c61bf7b3005a..f570bfc79db6 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -35,10 +35,10 @@ Onyx.connect({ callback: (val) => (credentials = val || {}), }); -let preferredLocale; +let nvpPreferredLocale; Onyx.connect({ key: ONYXKEYS.NVP_PREFERRED_LOCALE, - callback: (val) => (preferredLocale = val), + callback: (val) => (nvpPreferredLocale = val), }); /** @@ -250,7 +250,7 @@ function beginSignIn(login) { */ function beginAppleSignIn(idToken) { const {optimisticData, successData, failureData} = signInAttemptState(); - API.write('SignInWithApple', {idToken, preferredLocale}, {optimisticData, successData, failureData}); + API.write('SignInWithApple', {idToken, preferredLocale: nvpPreferredLocale}, {optimisticData, successData, failureData}); } /** @@ -261,7 +261,7 @@ function beginAppleSignIn(idToken) { */ function beginGoogleSignIn(token) { const {optimisticData, successData, failureData} = signInAttemptState(); - API.write('SignInWithGoogle', {token, preferredLocale}, {optimisticData, successData, failureData}); + API.write('SignInWithGoogle', {token, preferredLocale: nvpPreferredLocale}, {optimisticData, successData, failureData}); } /** From 3c9fbf791b3244f21ab7452aa2471d99db059ea3 Mon Sep 17 00:00:00 2001 From: VH Date: Fri, 15 Sep 2023 22:54:57 +0700 Subject: [PATCH 3/3] Use preferredLocale from Onyx because it's not part of sign in form --- .../ValidateCode/ValidateCodeModal.js | 2 +- src/libs/actions/Session/index.js | 17 ++++++++--------- src/pages/ValidateLoginPage/index.js | 5 +---- src/pages/ValidateLoginPage/index.website.js | 4 +--- .../ValidateCodeForm/BaseValidateCodeForm.js | 11 +++-------- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/components/ValidateCode/ValidateCodeModal.js b/src/components/ValidateCode/ValidateCodeModal.js index eabb21eea4a9..ceebc54a47af 100644 --- a/src/components/ValidateCode/ValidateCodeModal.js +++ b/src/components/ValidateCode/ValidateCodeModal.js @@ -39,7 +39,7 @@ const defaultProps = { }; function ValidateCodeModal(props) { - const signInHere = useCallback(() => Session.signInWithValidateCode(props.accountID, props.code, props.preferredLocale), [props.accountID, props.code, props.preferredLocale]); + const signInHere = useCallback(() => Session.signInWithValidateCode(props.accountID, props.code), [props.accountID, props.code]); return ( diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index b250c35cf664..117a092c3875 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -45,10 +45,10 @@ Onyx.connect({ callback: (val) => (credentials = val || {}), }); -let nvpPreferredLocale; +let preferredLocale; Onyx.connect({ key: ONYXKEYS.NVP_PREFERRED_LOCALE, - callback: (val) => (nvpPreferredLocale = val), + callback: (val) => (preferredLocale = val), }); /** @@ -260,7 +260,7 @@ function beginSignIn(login) { */ function beginAppleSignIn(idToken) { const {optimisticData, successData, failureData} = signInAttemptState(); - API.write('SignInWithApple', {idToken, preferredLocale: nvpPreferredLocale}, {optimisticData, successData, failureData}); + API.write('SignInWithApple', {idToken, preferredLocale}, {optimisticData, successData, failureData}); } /** @@ -271,7 +271,7 @@ function beginAppleSignIn(idToken) { */ function beginGoogleSignIn(token) { const {optimisticData, successData, failureData} = signInAttemptState(); - API.write('SignInWithGoogle', {token, preferredLocale: nvpPreferredLocale}, {optimisticData, successData, failureData}); + API.write('SignInWithGoogle', {token, preferredLocale}, {optimisticData, successData, failureData}); } /** @@ -327,9 +327,8 @@ function signInWithShortLivedAuthToken(email, authToken) { * * @param {String} validateCode 6 digit code required for login * @param {String} [twoFactorAuthCode] - * @param {String} [preferredLocale] Indicates which language to use when the user lands in the app */ -function signIn(validateCode, twoFactorAuthCode, preferredLocale = CONST.LOCALES.DEFAULT) { +function signIn(validateCode, twoFactorAuthCode) { const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -386,7 +385,7 @@ function signIn(validateCode, twoFactorAuthCode, preferredLocale = CONST.LOCALES }); } -function signInWithValidateCode(accountID, code, preferredLocale = CONST.LOCALES.DEFAULT, twoFactorAuthCode = '') { +function signInWithValidateCode(accountID, code, twoFactorAuthCode = '') { // If this is called from the 2fa step, get the validateCode directly from onyx // instead of the one passed from the component state because the state is changing when this method is called. const validateCode = twoFactorAuthCode ? credentials.validateCode : code; @@ -462,8 +461,8 @@ function signInWithValidateCode(accountID, code, preferredLocale = CONST.LOCALES }); } -function signInWithValidateCodeAndNavigate(accountID, validateCode, preferredLocale = CONST.LOCALES.DEFAULT, twoFactorAuthCode = '') { - signInWithValidateCode(accountID, validateCode, preferredLocale, twoFactorAuthCode); +function signInWithValidateCodeAndNavigate(accountID, validateCode, twoFactorAuthCode = '') { + signInWithValidateCode(accountID, validateCode, twoFactorAuthCode); Navigation.navigate(ROUTES.HOME); } diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 561c8512ca3d..0af978172822 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -6,7 +6,6 @@ import {propTypes as validateLinkPropTypes, defaultProps as validateLinkDefaultP import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; import ONYXKEYS from '../../ONYXKEYS'; import * as Session from '../../libs/actions/Session'; -import useLocalize from '../../hooks/useLocalize'; import Navigation from '../../libs/Navigation/Navigation'; const propTypes = { @@ -35,8 +34,6 @@ const defaultProps = { }; function ValidateLoginPage(props) { - const {preferredLocale} = useLocalize(); - useEffect(() => { const accountID = lodashGet(props.route.params, 'accountID', ''); const validateCode = lodashGet(props.route.params, 'validateCode', ''); @@ -46,7 +43,7 @@ function ValidateLoginPage(props) { // because we don't want to block the user with the interstitial page. Navigation.goBack(false); } else { - Session.signInWithValidateCodeAndNavigate(accountID, validateCode, preferredLocale); + Session.signInWithValidateCodeAndNavigate(accountID, validateCode); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/pages/ValidateLoginPage/index.website.js b/src/pages/ValidateLoginPage/index.website.js index 323779a7d420..4ac12b3193f3 100644 --- a/src/pages/ValidateLoginPage/index.website.js +++ b/src/pages/ValidateLoginPage/index.website.js @@ -7,7 +7,6 @@ import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndica import ValidateCodeModal from '../../components/ValidateCode/ValidateCodeModal'; import ONYXKEYS from '../../ONYXKEYS'; import * as Session from '../../libs/actions/Session'; -import useLocalize from '../../hooks/useLocalize'; import ExpiredValidateCodeModal from '../../components/ValidateCode/ExpiredValidateCodeModal'; import Navigation from '../../libs/Navigation/Navigation'; import CONST from '../../CONST'; @@ -49,7 +48,6 @@ const defaultProps = { }; function ValidateLoginPage(props) { - const {preferredLocale} = useLocalize(); const login = lodashGet(props, 'credentials.login', null); const autoAuthState = lodashGet(props, 'session.autoAuthState', CONST.AUTO_AUTH_STATE.NOT_STARTED); const accountID = lodashGet(props.route.params, 'accountID', ''); @@ -71,7 +69,7 @@ function ValidateLoginPage(props) { } // The user has initiated the sign in process on the same browser, in another tab. - Session.signInWithValidateCode(accountID, validateCode, preferredLocale); + Session.signInWithValidateCode(accountID, validateCode); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js index 51cb287f9564..c38e4dd3c4dd 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js @@ -51,9 +51,6 @@ const propTypes = { authToken: PropTypes.string, }), - /** Indicates which locale the user currently has selected */ - preferredLocale: PropTypes.string, - /** Information about the network */ network: networkPropTypes.isRequired, @@ -69,7 +66,6 @@ const defaultProps = { session: { authToken: null, }, - preferredLocale: CONST.LOCALES.DEFAULT, }; function BaseValidateCodeForm(props) { @@ -228,11 +224,11 @@ function BaseValidateCodeForm(props) { const accountID = lodashGet(props.credentials, 'accountID'); if (accountID) { - Session.signInWithValidateCode(accountID, validateCode, props.preferredLocale, twoFactorAuthCode); + Session.signInWithValidateCode(accountID, validateCode, twoFactorAuthCode); } else { - Session.signIn(validateCode, twoFactorAuthCode, props.preferredLocale); + Session.signIn(validateCode, twoFactorAuthCode); } - }, [props.account, props.credentials, props.preferredLocale, twoFactorAuthCode, validateCode]); + }, [props.account, props.credentials, twoFactorAuthCode, validateCode]); return ( <> @@ -323,7 +319,6 @@ export default compose( withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, credentials: {key: ONYXKEYS.CREDENTIALS}, - preferredLocale: {key: ONYXKEYS.NVP_PREFERRED_LOCALE}, session: {key: ONYXKEYS.SESSION}, }), withNetwork(),