diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 3f4f2c5ee360..7895820f2063 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -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'; @@ -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