Skip to content

Commit

Permalink
Merge pull request #2318 from Expensify/nikki-automatic-timezone
Browse files Browse the repository at this point in the history
Update timezone to update if user has it set to automatic
  • Loading branch information
thienlnam authored Apr 12, 2021
2 parents 995afc2 + 87c3b3d commit 0874880
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import Onyx, {withOnyx} from 'react-native-onyx';
import moment from 'moment';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {getNavigationModalCardStyle} from '../../../styles/styles';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import CONST from '../../../CONST';
Expand Down Expand Up @@ -41,6 +44,21 @@ import {
SettingsModalStackNavigator,
} from './ModalStackNavigators';

Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
callback: (val) => {
const timezone = lodashGet(val, 'timezone', {});
const currentTimezone = moment.tz.guess(true);

// If the current timezone is different than the user's timezone, and their timezone is set to automatic
// then update their timezone.
if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) {
timezone.selected = currentTimezone;
PersonalDetails.setPersonalDetails({timezone});
}
},
});

const RootStack = createCustomModalStackNavigator();

// When modal screen gets focused, update modal visibility in Onyx
Expand Down

0 comments on commit 0874880

Please sign in to comment.