Skip to content

Commit 7f948fe

Browse files
committed
Expensify#4517 avoid init check race conditions
1 parent 81e979c commit 7f948fe

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

src/libs/Navigation/AppNavigator/AuthScreens.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import WorkspaceSettingsDrawerNavigator from './WorkspaceSettingsDrawerNavigator
6464
import spacing from '../../../styles/utilities/spacing';
6565
import CardOverlay from '../../../components/CardOverlay';
6666
import defaultScreenOptions from './defaultScreenOptions';
67-
import DateUtils from '../../DateUtils';
6867

6968
const RootStack = createCustomModalStackNavigator();
7069

@@ -180,9 +179,6 @@ class AuthScreens extends React.Component {
180179
this.unsubscribeGroupShortcut = KeyboardShortcut.subscribe('K', () => {
181180
Navigation.navigate(ROUTES.NEW_GROUP);
182181
}, groupShortcutModifiers, true);
183-
setTimeout(() => {
184-
DateUtils.updateTimezone();
185-
}, 1000);
186182
}
187183

188184
shouldComponentUpdate(nextProps) {

src/libs/actions/PersonalDetails.js

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import lodashGet from 'lodash/get';
33
import lodashMerge from 'lodash/merge';
44
import Onyx from 'react-native-onyx';
55
import Str from 'expensify-common/lib/str';
6+
import moment from 'moment';
67
import ONYXKEYS from '../../ONYXKEYS';
78
import CONST from '../../CONST';
89
import NetworkConnection from '../NetworkConnection';
@@ -93,6 +94,38 @@ function formatPersonalDetails(personalDetailsList) {
9394
}, {});
9495
}
9596

97+
/**
98+
* Merges partial details object into the local store.
99+
*
100+
* @param {Object} details
101+
* @private
102+
*/
103+
function mergeLocalPersonalDetails(details) {
104+
// We are merging the partial details provided to this method with the existing details we have for the user so
105+
// that we don't overwrite any values that may exist in storage.
106+
const mergedDetails = lodashMerge(personalDetails[currentUserEmail], details);
107+
108+
// displayName is a generated field so we'll use the firstName and lastName + login to update it.
109+
mergedDetails.displayName = getDisplayName(currentUserEmail, mergedDetails);
110+
111+
// Update the associated Onyx keys
112+
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, mergedDetails);
113+
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, {[currentUserEmail]: mergedDetails});
114+
}
115+
116+
/**
117+
* Sets the personal details object for the current user
118+
*
119+
* @param {Object} details
120+
*/
121+
function setPersonalDetails(details) {
122+
API.PersonalDetails_Update({details: JSON.stringify(details)});
123+
if (details.timezone) {
124+
NameValuePair.set(CONST.NVP.TIMEZONE, details.timezone);
125+
}
126+
mergeLocalPersonalDetails(details);
127+
}
128+
96129
/**
97130
* Get the personal details for our organization
98131
* @returns {Promise}
@@ -120,6 +153,14 @@ function fetchPersonalDetails() {
120153
myPersonalDetails.firstName = lodashGet(data.personalDetailsList, [currentUserEmail, 'firstName'], '');
121154
myPersonalDetails.lastName = lodashGet(data.personalDetailsList, [currentUserEmail, 'lastName'], '');
122155

156+
157+
// Update user's timezone, if their timezone is set to automatic and
158+
// is different from current timezone
159+
const currentTimezone = moment.tz.guess(true);
160+
if (myPersonalDetails.timezone.automatic && myPersonalDetails.timezone.selected !== currentTimezone) {
161+
myPersonalDetails.timezone.selected = currentTimezone;
162+
}
163+
123164
// Set my personal details so they can be easily accessed and subscribed to on their own key
124165
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, myPersonalDetails);
125166
})
@@ -187,38 +228,6 @@ function getFromReportParticipants(reports) {
187228
});
188229
}
189230

190-
/**
191-
* Merges partial details object into the local store.
192-
*
193-
* @param {Object} details
194-
* @private
195-
*/
196-
function mergeLocalPersonalDetails(details) {
197-
// We are merging the partial details provided to this method with the existing details we have for the user so
198-
// that we don't overwrite any values that may exist in storage.
199-
const mergedDetails = lodashMerge(personalDetails[currentUserEmail], details);
200-
201-
// displayName is a generated field so we'll use the firstName and lastName + login to update it.
202-
mergedDetails.displayName = getDisplayName(currentUserEmail, mergedDetails);
203-
204-
// Update the associated Onyx keys
205-
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, mergedDetails);
206-
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, {[currentUserEmail]: mergedDetails});
207-
}
208-
209-
/**
210-
* Sets the personal details object for the current user
211-
*
212-
* @param {Object} details
213-
*/
214-
function setPersonalDetails(details) {
215-
API.PersonalDetails_Update({details: JSON.stringify(details)});
216-
if (details.timezone) {
217-
NameValuePair.set(CONST.NVP.TIMEZONE, details.timezone);
218-
}
219-
mergeLocalPersonalDetails(details);
220-
}
221-
222231
/**
223232
* Sets the onyx with the currency list from the network
224233
* @returns {Object}

0 commit comments

Comments
 (0)