-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12201 from Expensify/beaman-newTimezonePage
New timezone pages
- Loading branch information
Showing
10 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import lodashGet from 'lodash/get'; | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import moment from 'moment-timezone'; | ||
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../../components/withCurrentUserPersonalDetails'; | ||
import ScreenWrapper from '../../../components/ScreenWrapper'; | ||
import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; | ||
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; | ||
import ROUTES from '../../../ROUTES'; | ||
import CONST from '../../../CONST'; | ||
import Text from '../../../components/Text'; | ||
import styles from '../../../styles/styles'; | ||
import Navigation from '../../../libs/Navigation/Navigation'; | ||
import * as PersonalDetails from '../../../libs/actions/PersonalDetails'; | ||
import compose from '../../../libs/compose'; | ||
import Switch from '../../../components/Switch'; | ||
import MenuItemWithTopDescription from '../../../components/MenuItemWithTopDescription'; | ||
|
||
const propTypes = { | ||
...withLocalizePropTypes, | ||
...withCurrentUserPersonalDetailsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
...withCurrentUserPersonalDetailsDefaultProps, | ||
}; | ||
|
||
const TimezoneInitialPage = (props) => { | ||
const timezone = lodashGet(props.currentUserPersonalDetails, 'timezone', CONST.DEFAULT_TIME_ZONE); | ||
|
||
/** | ||
* Updates setting for automatic timezone selection. | ||
* Note: If we are updating automatically, we'll immediately calculate the user's timezone. | ||
* | ||
* @param {Boolean} isAutomatic | ||
*/ | ||
const updateAutomaticTimezone = (isAutomatic) => { | ||
PersonalDetails.updateAutomaticTimezone({ | ||
automatic: isAutomatic, | ||
selected: isAutomatic ? moment.tz.guess() : timezone.selected, | ||
}); | ||
}; | ||
|
||
return ( | ||
<ScreenWrapper> | ||
<HeaderWithCloseButton | ||
title={props.translate('timezonePage.timezone')} | ||
shouldShowBackButton | ||
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS_PROFILE)} | ||
onCloseButtonPress={() => Navigation.dismissModal(true)} | ||
/> | ||
<View style={[styles.ph5]}> | ||
<Text style={[styles.mb5]}> | ||
{props.translate('timezonePage.isShownOnProfile')} | ||
</Text> | ||
<View style={[styles.flexRow, styles.mb5, styles.alignItemsCenter, styles.justifyContentBetween]}> | ||
<Text> | ||
{props.translate('timezonePage.getLocationAutomatically')} | ||
</Text> | ||
<Switch | ||
isOn={timezone.automatic} | ||
onToggle={updateAutomaticTimezone} | ||
/> | ||
</View> | ||
</View> | ||
<MenuItemWithTopDescription | ||
title={timezone.selected} | ||
description={props.translate('timezonePage.timezone')} | ||
shouldShowRightIcon | ||
wrapperStyle={[styles.ph2, styles.mb3]} | ||
disabled={timezone.automatic} | ||
onPress={() => Navigation.navigate(ROUTES.SETTINGS_TIMEZONE_SELECT)} | ||
/> | ||
</ScreenWrapper> | ||
); | ||
}; | ||
|
||
TimezoneInitialPage.propTypes = propTypes; | ||
TimezoneInitialPage.defaultProps = defaultProps; | ||
TimezoneInitialPage.displayName = 'TimezoneInitialPage'; | ||
|
||
export default compose( | ||
withLocalize, | ||
withCurrentUserPersonalDetails, | ||
)(TimezoneInitialPage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import lodashGet from 'lodash/get'; | ||
import React, {Component} from 'react'; | ||
import _ from 'underscore'; | ||
import moment from 'moment-timezone'; | ||
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../../components/withCurrentUserPersonalDetails'; | ||
import ScreenWrapper from '../../../components/ScreenWrapper'; | ||
import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; | ||
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; | ||
import ROUTES from '../../../ROUTES'; | ||
import CONST from '../../../CONST'; | ||
import styles from '../../../styles/styles'; | ||
import Navigation from '../../../libs/Navigation/Navigation'; | ||
import * as PersonalDetails from '../../../libs/actions/PersonalDetails'; | ||
import compose from '../../../libs/compose'; | ||
import OptionsSelector from '../../../components/OptionsSelector'; | ||
import themeColors from '../../../styles/themes/default'; | ||
import * as Expensicons from '../../../components/Icon/Expensicons'; | ||
|
||
const propTypes = { | ||
...withLocalizePropTypes, | ||
...withCurrentUserPersonalDetailsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
...withCurrentUserPersonalDetailsDefaultProps, | ||
}; | ||
|
||
class TimezoneSelectPage extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.saveSelectedTimezone = this.saveSelectedTimezone.bind(this); | ||
this.filterShownTimezones = this.filterShownTimezones.bind(this); | ||
|
||
this.currentSelectedTimezone = lodashGet(props.currentUserPersonalDetails, 'timezone.selected', CONST.DEFAULT_TIME_ZONE.selected); | ||
this.allTimezones = _.chain(moment.tz.names()) | ||
.filter(timezone => !timezone.startsWith('Etc/GMT')) | ||
.map(timezone => ({ | ||
text: timezone, | ||
keyForList: timezone, | ||
|
||
// Add green checkmark icon & bold the timezone text | ||
customIcon: timezone === this.currentSelectedTimezone | ||
? {src: Expensicons.Checkmark, color: themeColors.success} | ||
: null, | ||
isUnread: timezone === this.currentSelectedTimezone, | ||
})) | ||
.value(); | ||
|
||
this.state = { | ||
timezoneInputText: this.currentSelectedTimezone, | ||
timezoneOptions: this.allTimezones, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {Object} timezone | ||
* @param {String} timezone.text | ||
*/ | ||
saveSelectedTimezone({text}) { | ||
PersonalDetails.updateSelectedTimezone(text); | ||
} | ||
|
||
/** | ||
* @param {String} searchText | ||
*/ | ||
filterShownTimezones(searchText) { | ||
this.setState({ | ||
timezoneInputText: searchText, | ||
timezoneOptions: _.filter(this.allTimezones, (tz => tz.text.toLowerCase().includes(searchText.toLowerCase()))), | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<ScreenWrapper> | ||
<HeaderWithCloseButton | ||
title={this.props.translate('timezonePage.timezone')} | ||
shouldShowBackButton | ||
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS_TIMEZONE)} | ||
onCloseButtonPress={() => Navigation.dismissModal(true)} | ||
/> | ||
<OptionsSelector | ||
textInputLabel={this.props.translate('timezonePage.timezone')} | ||
value={this.state.timezoneInputText} | ||
onChangeText={this.filterShownTimezones} | ||
onSelectRow={this.saveSelectedTimezone} | ||
optionHoveredStyle={styles.hoveredComponentBG} | ||
sections={[{data: this.state.timezoneOptions}]} | ||
shouldHaveOptionSeparator | ||
/> | ||
</ScreenWrapper> | ||
); | ||
} | ||
} | ||
|
||
TimezoneSelectPage.propTypes = propTypes; | ||
TimezoneSelectPage.defaultProps = defaultProps; | ||
|
||
export default compose( | ||
withLocalize, | ||
withCurrentUserPersonalDetails, | ||
)(TimezoneSelectPage); |