Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New timezone pages #12201

Merged
merged 29 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9704e1e
Set up routes for new Timezone pages
Beamanator Oct 27, 2022
c9cad55
New timezone initial page
Beamanator Oct 27, 2022
bcae580
New timezone select page
Beamanator Oct 27, 2022
b173e21
New translations
Beamanator Oct 27, 2022
f1bc673
New timezone commands
Beamanator Oct 27, 2022
cfbdb16
Merge branch 'main' of github.com:Expensify/App into beaman-newTimezo…
Beamanator Oct 28, 2022
8e3bf2e
Add vertical padding to timezone button
Beamanator Oct 28, 2022
b9fd35a
Update selected tz then nav to tz init page
Beamanator Oct 28, 2022
2221e56
Fill out timezone select page & filtering
Beamanator Oct 28, 2022
06dfa1d
Move custom icon to Option props
Beamanator Oct 28, 2022
05e67bf
Fix where timezone comes from
Beamanator Oct 28, 2022
d2afbd9
Fix lots of lint issues
Beamanator Oct 28, 2022
c2c7e70
Add prop for option separator
Beamanator Oct 28, 2022
9e6eb14
Merge branch 'main' of github.com:Expensify/App into beaman-newTimezo…
Beamanator Oct 31, 2022
45951b4
Add all prop comments
Beamanator Oct 31, 2022
c51cc57
Get icon props safely
Beamanator Oct 31, 2022
a7758c8
Add function description
Beamanator Oct 31, 2022
c02e802
Match any timezone that includes searched timezone text
Beamanator Oct 31, 2022
cf1ca69
Merge branch 'main' of github.com:Expensify/App into beaman-newTimezo…
Beamanator Nov 7, 2022
5213617
Merge remote-tracking branch 'origin/main' into beaman-newTimezonePage
cristipaval Nov 15, 2022
97df428
Merge remote-tracking branch 'origin/main' into beaman-newTimezonePage
cristipaval Nov 17, 2022
d61aac0
Fix updateSelectedTimezone operation in PersonalDetails.
cristipaval Nov 21, 2022
467760b
Fix js lint errors
cristipaval Nov 21, 2022
818ac83
Update src/languages/es.js
cristipaval Nov 22, 2022
f13ab5f
Rename routing constants
cristipaval Nov 22, 2022
1ab9ee9
Update doc in TimezoneInitialPage.js
cristipaval Nov 22, 2022
4c1910e
Merge remote-tracking branch 'origin/main' into beaman-newTimezonePage
cristipaval Nov 28, 2022
2be55f9
Fix checkmark color in timezone selector page.
cristipaval Nov 28, 2022
717fbc4
Update doc in TimezoneInitialPage.js
cristipaval Dec 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default {
HOME: '',
SETTINGS: 'settings',
SETTINGS_PROFILE: 'settings/profile',
SETTINGS_TIMEZONE_INITIAL: 'settings/profile/timezone',
SETTINGS_TIMEZONE_SELECT: 'settings/profile/timezone/select',
SETTINGS_PREFERENCES: 'settings/preferences',
SETTINGS_WORKSPACES: 'settings/workspaces',
SETTINGS_SECURITY: 'settings/security',
Expand Down
15 changes: 15 additions & 0 deletions src/components/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const propTypes = {
/** Whether this option should be disabled */
isDisabled: PropTypes.bool,

/** Whether to show a line separating options in list */
shouldHaveOptionSeparator: PropTypes.bool,

style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),

...withLocalizePropTypes,
Expand All @@ -90,6 +93,7 @@ const defaultProps = {
isDisabled: false,
optionIsFocused: false,
style: null,
shouldHaveOptionSeparator: false,
};

const OptionRow = (props) => {
Expand Down Expand Up @@ -164,6 +168,7 @@ const OptionRow = (props) => {
props.optionIsFocused ? styles.sidebarLinkActive : null,
hovered && !props.optionIsFocused ? props.hoverStyle : null,
props.isDisabled && styles.cursorDisabled,
props.shouldHaveOptionSeparator && styles.borderTop,
]}
>
<View accessibilityHint={props.accessibilityHint} style={sidebarInnerRowStyle}>
Expand Down Expand Up @@ -266,6 +271,16 @@ const OptionRow = (props) => {
<Icon src={Expensicons.Pin} height={16} width={16} />
</View>
)}
{Boolean(props.option.customIcon) && (
<View>
<Icon
src={lodashGet(props.option, 'customIcon.src', '')}
height={16}
width={16}
fill={lodashGet(props.option, 'customIcon.color')}
/>
</View>
)}
</View>
)}
</TouchableOpacity>
Expand Down
1 change: 1 addition & 0 deletions src/components/OptionsList/BaseOptionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class BaseOptionsList extends Component {
hideAdditionalOptionStates={this.props.hideAdditionalOptionStates}
forceTextUnreadStyle={this.props.forceTextUnreadStyle}
isDisabled={this.props.isDisabled || section.isDisabled}
shouldHaveOptionSeparator={this.props.shouldHaveOptionSeparator}
/>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/OptionsList/optionsListPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const propTypes = {

/** Callback to execute when the SectionList lays out */
onLayout: PropTypes.func,

/** Whether to show a line separating options in list */
shouldHaveOptionSeparator: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -100,6 +103,7 @@ const defaultProps = {
optionMode: undefined,
isDisabled: false,
onLayout: undefined,
shouldHaveOptionSeparator: false,
};

export {propTypes, defaultProps};
1 change: 1 addition & 0 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class BaseOptionsSelector extends Component {
forceTextUnreadStyle={this.props.forceTextUnreadStyle}
showTitleTooltip={this.props.showTitleTooltip}
isDisabled={this.props.isDisabled}
shouldHaveOptionSeparator={this.props.shouldHaveOptionSeparator}
/>
) : <FullScreenLoadingIndicator />;
return (
Expand Down
4 changes: 4 additions & 0 deletions src/components/OptionsSelector/optionsSelectorPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const propTypes = {

/** Whether to show options list */
shouldShowOptions: PropTypes.bool,

/** Whether to show a line separating options in list */
shouldHaveOptionSeparator: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -113,6 +116,7 @@ const defaultProps = {
shouldShowOptions: true,
disableArrowKeysActions: false,
isDisabled: false,
shouldHaveOptionSeparator: false,
};

export {propTypes, defaultProps};
9 changes: 9 additions & 0 deletions src/components/optionPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export default PropTypes.shape({
// Whether the option has an outstanding IOU
hasOutstandingIOU: PropTypes.bool,

// Custom icon to render on the right side of the option
customIcon: PropTypes.shape({
// The icon source
src: PropTypes.func,

// The color of the icon
color: PropTypes.string,
}),

// List of participants of the report
participantsList: PropTypes.arrayOf(participantPropTypes),

Expand Down
5 changes: 5 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ export default {
offline: 'Offline',
syncing: 'Syncing',
},
timezonePage: {
timezone: 'Timezone',
isShownOnProfile: 'Your timezone is shown on your profile.',
getLocationAutomatically: 'Automatically determine your location.',
},
addSecondaryLoginPage: {
addPhoneNumber: 'Add phone number',
addEmailAddress: 'Add email address',
Expand Down
5 changes: 5 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ export default {
offline: 'Desconectado',
syncing: 'Sincronizando',
},
timezonePage: {
timezone: 'Zona horaria',
isShownOnProfile: '',
getLocationAutomatically: '',
cristipaval marked this conversation as resolved.
Show resolved Hide resolved
},
addSecondaryLoginPage: {
addPhoneNumber: 'Agregar número de teléfono',
addEmailAddress: 'Agregar dirección de email',
Expand Down
14 changes: 14 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ const SettingsModalStackNavigator = createModalStackNavigator([
},
name: 'Settings_Profile',
},
{
getComponent: () => {
const SettingsTimezoneInitialPage = require('../../../pages/settings/Profile/TimezoneInitialPage').default;
return SettingsTimezoneInitialPage;
},
name: 'Settings_Timezone_Init',
NikkiWines marked this conversation as resolved.
Show resolved Hide resolved
},
{
getComponent: () => {
const SettingsTimezoneSelectPage = require('../../../pages/settings/Profile/TimezoneSelectPage').default;
return SettingsTimezoneSelectPage;
},
name: 'Settings_Timezone_Select',
},
{
getComponent: () => {
const SettingsAddSecondaryLoginPage = require('../../../pages/settings/AddSecondaryLoginPage').default;
Expand Down
8 changes: 8 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export default {
path: ROUTES.SETTINGS_PROFILE,
exact: true,
},
Settings_Timezone_Init: {
NikkiWines marked this conversation as resolved.
Show resolved Hide resolved
path: ROUTES.SETTINGS_TIMEZONE_INITIAL,
exact: true,
},
Settings_Timezone_Select: {
path: ROUTES.SETTINGS_TIMEZONE_SELECT,
exact: true,
},
Settings_About: {
path: ROUTES.SETTINGS_ABOUT,
exact: true,
Expand Down
53 changes: 53 additions & 0 deletions src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import * as LoginUtils from '../LoginUtils';
import * as ReportUtils from '../ReportUtils';
import Growl from '../Growl';
import * as Localize from '../Localize';
import ROUTES from '../../ROUTES';
import Navigation from '../Navigation/Navigation';

let currentUserEmail = '';
Onyx.connect({
Expand Down Expand Up @@ -285,6 +287,55 @@ function updateProfile(firstName, lastName, pronouns, timezone) {
});
}

/**
* Updates timezone's 'automatic' setting, and updates
* selected timezone if set to automatically update.
*
* @param {Object} timezone
* @param {Boolean} timezone.automatic
* @param {String} timezone.selected
*/
function updateAutomaticTimezone(timezone) {
API.write('UpdateAutomaticTimezone', {
timezone: JSON.stringify(timezone),
}, {
optimisticData: [{
NikkiWines marked this conversation as resolved.
Show resolved Hide resolved
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
value: {
[currentUserEmail]: {
timezone,
},
},
}],
});
}

/**
* Updates user's 'selected' timezone, then navigates to the
* initial Timezone page.
*
* @param {String} selectedTimezone
*/
function updateSelectedTimezone(selectedTimezone) {
API.write('UpdateSelectedTimezone', {
text: selectedTimezone,
}, {
optimisticData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
value: {
[currentUserEmail]: {
timezone: {
selected: selectedTimezone,
},
},
},
}],
});
Navigation.navigate(ROUTES.SETTINGS_TIMEZONE_INITIAL);
}

/**
* Fetches the local currency based on location and sets currency code/symbol to Onyx
*/
Expand Down Expand Up @@ -398,4 +449,6 @@ export {
extractFirstAndLastNameFromAvailableDetails,
updateProfile,
clearAvatarErrors,
updateAutomaticTimezone,
updateSelectedTimezone,
};
85 changes: 85 additions & 0 deletions src/pages/settings/Profile/TimezoneInitialPage.js
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 timezone updating automatically.
* Note: If we are updating automatically, we'll immediately caltulate user timezone.
cristipaval marked this conversation as resolved.
Show resolved Hide resolved
*
* @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);
Loading