From 9cd3d4d873d0e3523ef882d1506bc29c0db92af4 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Mon, 20 Mar 2023 16:57:31 -0400 Subject: [PATCH 1/8] pass preferred locale to api on sign in --- 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 edf29b06940..5b7bd3a24cf 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -244,8 +244,9 @@ function signInWithShortLivedAuthToken(email, authToken) { * @param {String} password This will be removed after passwordless beta ends * @param {String} [validateCode] Code for passwordless login * @param {String} [twoFactorAuthCode] + * @param {String} [preferredLocale] Indicates which language to use when the user lands in the app */ -function signIn(password, validateCode, twoFactorAuthCode) { +function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CONST.DEFAULT_LOCALE) { const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.MERGE, @@ -265,6 +266,11 @@ function signIn(password, validateCode, twoFactorAuthCode) { isLoading: false, }, }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.NVP_PREFERRED_LOCALE, + value: preferredLocale, + }, ]; const failureData = [ @@ -277,7 +283,7 @@ function signIn(password, validateCode, twoFactorAuthCode) { }, ]; - const params = {twoFactorAuthCode, email: credentials.login}; + const params = {twoFactorAuthCode, email: credentials.login, preferredLocale}; // Conditionally pass a password or validateCode to command since we temporarily allow both flows if (validateCode) { From beb16059d7f81f893f3ceb989b97e45e6454e42b Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Mon, 20 Mar 2023 17:06:17 -0400 Subject: [PATCH 2/8] subscribe ValidateCodeForm to preferredLocale in onyx and pass when signing in --- src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js index 2e9b81d0218..5e3d00403e8 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js @@ -45,6 +45,9 @@ const propTypes = { login: PropTypes.string, }), + /** Indicates which locale the user currently has selected */ + preferredLocale: PropTypes.string, + /** Information about the network */ network: networkPropTypes.isRequired, @@ -58,6 +61,7 @@ const propTypes = { const defaultProps = { account: {}, credentials: {}, + preferredLocale: CONST.DEFAULT_LOCALE, }; class BaseValidateCodeForm extends React.Component { @@ -180,7 +184,7 @@ class BaseValidateCodeForm extends React.Component { if (accountID) { Session.signInWithValidateCode(accountID, this.state.validateCode, this.state.twoFactorAuthCode); } else { - Session.signIn('', this.state.validateCode, this.state.twoFactorAuthCode); + Session.signIn('', this.state.validateCode, this.state.twoFactorAuthCode, this.props.preferredLocale); } } @@ -271,6 +275,7 @@ export default compose( withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, credentials: {key: ONYXKEYS.CREDENTIALS}, + preferredLocale: {key: ONYXKEYS.NVP_PREFERRED_LOCALE}, }), withToggleVisibilityView, withNetwork(), From db3a87d92a1d60ccdb6a87b00a94f708a1466112 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Mon, 20 Mar 2023 17:08:05 -0400 Subject: [PATCH 3/8] subscribe PasswordForm to preferredLocale in onyx and pass when signing in --- src/pages/signin/PasswordForm.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/signin/PasswordForm.js b/src/pages/signin/PasswordForm.js index 91b8ac27be9..8d0c0855d1d 100755 --- a/src/pages/signin/PasswordForm.js +++ b/src/pages/signin/PasswordForm.js @@ -38,6 +38,9 @@ const propTypes = { isLoading: PropTypes.bool, }), + /** Indicates which locale the user currently has selected */ + preferredLocale: PropTypes.string, + /** Information about the network */ network: networkPropTypes.isRequired, @@ -47,6 +50,7 @@ const propTypes = { const defaultProps = { account: {}, + preferredLocale: CONST.DEFAULT_LOCALE, }; class PasswordForm extends React.Component { @@ -160,7 +164,7 @@ class PasswordForm extends React.Component { formError: {}, }); - Session.signIn(password, '', twoFactorCode); + Session.signIn(password, '', twoFactorCode, this.props.preferredLocale); } render() { @@ -240,6 +244,7 @@ export default compose( withLocalize, withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, + preferredLocale: {key: ONYXKEYS.NVP_PREFERRED_LOCALE}, }), withToggleVisibilityView, withNetwork(), From 13812f427b835dfd86aeceb06baba1aac033bbe3 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Mon, 20 Mar 2023 18:14:11 -0400 Subject: [PATCH 4/8] Only send the preferred locale to the api if its different than the default --- src/libs/actions/Session/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 5b7bd3a24cf..7e47bff1174 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -246,7 +246,7 @@ function signInWithShortLivedAuthToken(email, authToken) { * @param {String} [twoFactorAuthCode] * @param {String} [preferredLocale] Indicates which language to use when the user lands in the app */ -function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CONST.DEFAULT_LOCALE) { +function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = '') { const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.MERGE, @@ -283,7 +283,7 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CON }, ]; - const params = {twoFactorAuthCode, email: credentials.login, preferredLocale}; + const params = {twoFactorAuthCode, email: credentials.login}; // Conditionally pass a password or validateCode to command since we temporarily allow both flows if (validateCode) { @@ -292,6 +292,11 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CON params.password = password; } + // If the user chooses a language other than the default, pass that to the API so it'll be set on their account upon sign in + if (preferredLocale !== CONST.DEFAULT_LOCALE) { + params.preferredLocale = preferredLocale; + } + API.write('SigninUser', params, {optimisticData, successData, failureData}); } From 30860b5ec67c0167a00f514cbd835ff108cc45d0 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Mon, 20 Mar 2023 18:18:40 -0400 Subject: [PATCH 5/8] remove unncessary optimistic data --- src/libs/actions/Session/index.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 7e47bff1174..7d292d86e15 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -266,11 +266,6 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = '') isLoading: false, }, }, - { - onyxMethod: CONST.ONYX.METHOD.MERGE, - key: ONYXKEYS.NVP_PREFERRED_LOCALE, - value: preferredLocale, - }, ]; const failureData = [ From 3f8151cd34a772220ba999714546947835a94ce7 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Tue, 21 Mar 2023 13:57:10 -0400 Subject: [PATCH 6/8] improve comment explanation --- src/libs/actions/Session/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 7d292d86e15..0e92bc51fde 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -288,6 +288,7 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = '') } // If the user chooses a language other than the default, pass that to the API so it'll be set on their account upon sign in + // We only do this for non-default locales because that indicates they took an explicit action to set their language if (preferredLocale !== CONST.DEFAULT_LOCALE) { params.preferredLocale = preferredLocale; } From ed34ed61b59eaaeedcbe1bcb19853494b0a7d6b9 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 22 Mar 2023 11:53:18 -0400 Subject: [PATCH 7/8] Only pass preferred locale when set --- src/libs/actions/Session/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 0e92bc51fde..389fd8e88c0 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -246,7 +246,7 @@ function signInWithShortLivedAuthToken(email, authToken) { * @param {String} [twoFactorAuthCode] * @param {String} [preferredLocale] Indicates which language to use when the user lands in the app */ -function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = '') { +function signIn(password, validateCode, twoFactorAuthCode, preferredLocale) { const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.MERGE, @@ -289,7 +289,7 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = '') // If the user chooses a language other than the default, pass that to the API so it'll be set on their account upon sign in // We only do this for non-default locales because that indicates they took an explicit action to set their language - if (preferredLocale !== CONST.DEFAULT_LOCALE) { + if (preferredLocale && preferredLocale !== CONST.DEFAULT_LOCALE) { params.preferredLocale = preferredLocale; } From 5814fb89cd485b805b46b8aee61b410247dd857d Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Fri, 24 Mar 2023 11:00:24 -0400 Subject: [PATCH 8/8] Always include preferredLocale from signin page --- src/libs/actions/Session/index.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 389fd8e88c0..e03c26e1bb6 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -246,7 +246,7 @@ function signInWithShortLivedAuthToken(email, authToken) { * @param {String} [twoFactorAuthCode] * @param {String} [preferredLocale] Indicates which language to use when the user lands in the app */ -function signIn(password, validateCode, twoFactorAuthCode, preferredLocale) { +function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CONST.DEFAULT_LOCALE) { const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.MERGE, @@ -278,7 +278,7 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale) { }, ]; - const params = {twoFactorAuthCode, email: credentials.login}; + const params = {twoFactorAuthCode, email: credentials.login, preferredLocale}; // Conditionally pass a password or validateCode to command since we temporarily allow both flows if (validateCode) { @@ -287,12 +287,6 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale) { params.password = password; } - // If the user chooses a language other than the default, pass that to the API so it'll be set on their account upon sign in - // We only do this for non-default locales because that indicates they took an explicit action to set their language - if (preferredLocale && preferredLocale !== CONST.DEFAULT_LOCALE) { - params.preferredLocale = preferredLocale; - } - API.write('SigninUser', params, {optimisticData, successData, failureData}); }