Skip to content

Commit

Permalink
Use preferredLocale from Onyx because it's not part of sign in form
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangzinh committed Sep 15, 2023
1 parent eba0d9f commit 3c9fbf7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/ValidateCode/ValidateCodeModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<View style={styles.deeplinkWrapperContainer}>
Expand Down
17 changes: 8 additions & 9 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});

/**
Expand Down Expand Up @@ -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});
}

/**
Expand All @@ -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});
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 1 addition & 4 deletions src/pages/ValidateLoginPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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', '');
Expand All @@ -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
}, []);
Expand Down
4 changes: 1 addition & 3 deletions src/pages/ValidateLoginPage/index.website.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', '');
Expand All @@ -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
}, []);

Expand Down
11 changes: 3 additions & 8 deletions src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -69,7 +66,6 @@ const defaultProps = {
session: {
authToken: null,
},
preferredLocale: CONST.LOCALES.DEFAULT,
};

function BaseValidateCodeForm(props) {
Expand Down Expand Up @@ -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 (
<>
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 3c9fbf7

Please sign in to comment.