Skip to content

Commit

Permalink
Merge pull request #16326 from Expensify/set-language-on-signin
Browse files Browse the repository at this point in the history
Pass preferred locale to API on sign in
  • Loading branch information
puneetlath authored Mar 24, 2023
2 parents 1de4021 + ab35cfb commit 7b8f085
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,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,
Expand Down Expand Up @@ -308,7 +309,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) {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/signin/PasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -47,6 +50,7 @@ const propTypes = {

const defaultProps = {
account: {},
preferredLocale: CONST.DEFAULT_LOCALE,
};

class PasswordForm extends React.Component {
Expand Down Expand Up @@ -160,7 +164,7 @@ class PasswordForm extends React.Component {
formError: {},
});

Session.signIn(password, '', twoFactorCode);
Session.signIn(password, '', twoFactorCode, this.props.preferredLocale);
}

render() {
Expand Down Expand Up @@ -240,6 +244,7 @@ export default compose(
withLocalize,
withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
preferredLocale: {key: ONYXKEYS.NVP_PREFERRED_LOCALE},
}),
withToggleVisibilityView,
withNetwork(),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -58,6 +61,7 @@ const propTypes = {
const defaultProps = {
account: {},
credentials: {},
preferredLocale: CONST.DEFAULT_LOCALE,
};

class BaseValidateCodeForm extends React.Component {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -271,6 +275,7 @@ export default compose(
withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
credentials: {key: ONYXKEYS.CREDENTIALS},
preferredLocale: {key: ONYXKEYS.NVP_PREFERRED_LOCALE},
}),
withToggleVisibilityView,
withNetwork(),
Expand Down

0 comments on commit 7b8f085

Please sign in to comment.