Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember preferred locale on signup/login #5019

Merged
merged 2 commits into from
Sep 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import WorkspaceSettingsDrawerNavigator from './WorkspaceSettingsDrawerNavigator
import spacing from '../../../styles/utilities/spacing';
import CardOverlay from '../../../components/CardOverlay';
import defaultScreenOptions from './defaultScreenOptions';
import * as API from '../../API';
import {setLocale} from '../../actions/App';

Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
Expand All @@ -87,6 +89,12 @@ Onyx.connect({
},
});

let currentPreferredLocale;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: val => currentPreferredLocale = val || CONST.DEFAULT_LOCALE,
});

const RootStack = createCustomModalStackNavigator();

// We want to delay the re-rendering for components(e.g. ReportActionCompose)
Expand Down Expand Up @@ -158,7 +166,19 @@ class AuthScreens extends React.Component {

// Fetch some data we need on initialization
NameValuePair.get(CONST.NVP.PRIORITY_MODE, ONYXKEYS.NVP_PRIORITY_MODE, 'default');
NameValuePair.get(CONST.NVP.PREFERRED_LOCALE, ONYXKEYS.NVP_PREFERRED_LOCALE, 'en');

API.Get({
returnValueList: 'nameValuePairs',
nvpNames: ONYXKEYS.NVP_PREFERRED_LOCALE,
}).then((response) => {
const preferredLocale = response.nameValuePairs.preferredLocale || CONST.DEFAULT_LOCALE;
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
if (currentPreferredLocale !== CONST.DEFAULT_LOCALE && preferredLocale !== currentPreferredLocale) {
MonilBhavsar marked this conversation as resolved.
Show resolved Hide resolved
setLocale(currentPreferredLocale);
} else {
Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, preferredLocale);
}
});

PersonalDetails.fetchPersonalDetails();
User.getUserDetails();
User.getBetas();
Expand Down