@@ -3,6 +3,7 @@ import lodashGet from 'lodash/get';
3
3
import lodashMerge from 'lodash/merge' ;
4
4
import Onyx from 'react-native-onyx' ;
5
5
import Str from 'expensify-common/lib/str' ;
6
+ import moment from 'moment' ;
6
7
import ONYXKEYS from '../../ONYXKEYS' ;
7
8
import CONST from '../../CONST' ;
8
9
import NetworkConnection from '../NetworkConnection' ;
@@ -93,6 +94,38 @@ function formatPersonalDetails(personalDetailsList) {
93
94
} , { } ) ;
94
95
}
95
96
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
+
96
129
/**
97
130
* Get the personal details for our organization
98
131
* @returns {Promise }
@@ -120,6 +153,14 @@ function fetchPersonalDetails() {
120
153
myPersonalDetails . firstName = lodashGet ( data . personalDetailsList , [ currentUserEmail , 'firstName' ] , '' ) ;
121
154
myPersonalDetails . lastName = lodashGet ( data . personalDetailsList , [ currentUserEmail , 'lastName' ] , '' ) ;
122
155
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
+
123
164
// Set my personal details so they can be easily accessed and subscribed to on their own key
124
165
Onyx . merge ( ONYXKEYS . MY_PERSONAL_DETAILS , myPersonalDetails ) ;
125
166
} )
@@ -187,38 +228,6 @@ function getFromReportParticipants(reports) {
187
228
} ) ;
188
229
}
189
230
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
-
222
231
/**
223
232
* Sets the onyx with the currency list from the network
224
233
* @returns {Object }
0 commit comments