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

Update profilePage to include timezone #1717

Merged
merged 15 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export default {
// Contains all the personalDetails the user has access to
PERSONAL_DETAILS: 'personalDetails',

// Contains the user preference for the LHN priority mode
PRIORITY_MODE: 'priorityMode',

// Indicates whether an update is available and ready to beinstalled.
UPDATE_AVAILABLE: 'updateAvailable',

Expand All @@ -53,8 +50,12 @@ export default {
BETAS: 'betas',

// NVP keys
// Contains the user's payPalMe address
NVP_PAYPAL_ME_ADDRESS: 'nvp_paypalMeAddress',

// Contains the user preference for the LHN priority mode
NVP_PRIORITY_MODE: 'nvp_priorityMode',
marcaaron marked this conversation as resolved.
Show resolved Hide resolved

// Collection Keys
COLLECTION: {
REPORT: 'report_',
Expand Down
12 changes: 6 additions & 6 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import CONFIG from '../../../CONFIG';
import {fetchCountryCodeByRequestIP} from '../../actions/GeoLocation';
import KeyboardShortcut from '../../KeyboardShortcut';
import Navigation from '../Navigation';
import {getBetas} from '../../actions/User';
import * as User from '../../actions/User';
import NameValuePair from '../../actions/NameValuePair';

// Main drawer navigator
Expand Down Expand Up @@ -69,10 +69,10 @@ class AuthScreens extends React.Component {
}).then(subscribeToReportCommentEvents);

// Fetch some data we need on initialization
NameValuePair.get(CONST.NVP.PRIORITY_MODE, ONYXKEYS.PRIORITY_MODE, 'default');
NameValuePair.get(CONST.NVP.PRIORITY_MODE, ONYXKEYS.NVP_PRIORITY_MODE, 'default');
PersonalDetails.fetch();
PersonalDetails.fetchTimezone();
getBetas();
User.fetch();
User.getBetas();
fetchAllReports(true, true);
fetchCountryCodeByRequestIP();
UnreadIndicatorUpdater.listenForReportChanges();
Expand All @@ -85,8 +85,8 @@ class AuthScreens extends React.Component {
return;
}
PersonalDetails.fetch();
PersonalDetails.fetchTimezone();
getBetas();
User.fetch();
User.getBetas();
}, 1000 * 60 * 30);

Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER);
Expand Down
18 changes: 2 additions & 16 deletions src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function formatPersonalDetails(personalDetailsList) {
const avatar = getAvatar(personalDetailsResponse, login);
const displayName = getDisplayName(login, personalDetailsResponse);
const pronouns = lodashGet(personalDetailsResponse, 'pronouns', '');
const timezone = lodashGet(personalDetailsResponse, 'timeZone', CONST.DEFAULT_TIME_ZONE);

return {
...finalObject,
Expand All @@ -96,26 +97,12 @@ function formatPersonalDetails(personalDetailsList) {
avatar,
displayName,
pronouns,
timezone,
},
};
}, {});
}

/**
* Get the timezone of the logged in user
*/
function fetchTimezone() {
API.Get({
returnValueList: 'nameValuePairs',
name: 'timeZone',
})
.then((response) => {
const timezone = lodashGet(response.nameValuePairs, [CONST.NVP.TIMEZONE], CONST.DEFAULT_TIME_ZONE);
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, {timezone});
})
.catch(error => console.debug('Error fetching user timezone', error));
}

/**
* Get the personal details for our organization
*/
Expand Down Expand Up @@ -240,7 +227,6 @@ NetworkConnection.onReconnect(fetch);

export {
fetch,
fetchTimezone,
getFromReportParticipants,
getDisplayName,
getDefaultAvatar,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/migrateOnyx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import RenameActiveClientsKey from './migrations/RenameActiveClientsKey';
import RenamePriorityModeKey from './migrations/RenamePriorityModeKey';

export default function () {
const startTime = Date.now();
Expand All @@ -8,6 +9,7 @@ export default function () {
// Add all migrations to an array so they are executed in order
const migrationPromises = [
RenameActiveClientsKey,
RenamePriorityModeKey,
];

// Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the
Expand Down
33 changes: 33 additions & 0 deletions src/libs/migrations/RenamePriorityModeKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import ONYXKEYS from '../../ONYXKEYS';

// This migration changes the name of the Onyx key NVP_PRIORITY_MODE from priorityMode to nvp_priorityMode
export default function () {
return new Promise((resolve) => {
// Connect to the old key in Onyx to get the old value of priorityMode
// then set the new key nvp_priorityMode to hold the old data
// finally remove the old key by setting the value to null
const connectionID = Onyx.connect({
key: 'priorityMode',
callback: (oldPriorityMode) => {
Onyx.disconnect(connectionID);

// Fail early here because there is nothing to migrate
if (_.isEmpty(oldPriorityMode)) {
console.debug('[Migrate Onyx] Skipped migration RenamePriorityModeKey');
return resolve();
}

Onyx.multiSet({
priorityMode: null,
[ONYXKEYS.NVP_PRIORITY_MODE]: oldPriorityMode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda of unrelated but random thought here is that we should probably not reference ONYXKEYS in migration files since the migration is "forever" even tho the constant in Onyx could possibly change. Nothing to do here just a weird thought I guess.

})
.then(() => {
console.debug('[Migrate Onyx] Ran migration RenamePriorityModeKey');
resolve();
});
},
});
});
}
2 changes: 2 additions & 0 deletions src/pages/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const ProfilePage = ({personalDetails, route}) => {
</Text>
<Text style={[styles.textP]} numberOfLines={1}>
{moment().tz(profileDetails.timezone.selected).format('LT')}
{' '}
{moment().tz(profileDetails.timezone.selected).zoneAbbr()}
</Text>
</View>
) : null}
Expand Down
17 changes: 9 additions & 8 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ const HeaderView = (props) => {
Navigation.navigate(ROUTES.getProfileRoute(participants[0]));
}
}}
style={[styles.flexRow, styles.alignItemsCenter]}
>
<MultipleAvatars avatarImageURLs={props.report.icons} />
<View style={[styles.flex1, styles.flexRow]}>
<OptionRowTitle
option={reportOption}
tooltipEnabled
numberOfLines={2}
style={[styles.headerText]}
/>
</View>
</Pressable>
<View style={[styles.flex1, styles.flexRow]}>
<OptionRowTitle
option={reportOption}
tooltipEnabled
numberOfLines={2}
style={[styles.headerText]}
/>
</View>
<View style={[styles.reportOptions, styles.flexRow]}>
<Pressable
onPress={() => togglePinnedState(props.report)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default compose(
key: ONYXKEYS.CURRENTLY_VIEWED_REPORTID,
},
priorityMode: {
key: ONYXKEYS.PRIORITY_MODE,
key: ONYXKEYS.NVP_PRIORITY_MODE,
},
}),
)(SidebarLinks);
4 changes: 2 additions & 2 deletions src/pages/settings/PreferencesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PreferencesPage = ({priorityMode}) => (
{/* placeholder from appearing as a selection option. */}
<RNPickerSelect
onValueChange={
mode => NameValuePair.set(CONST.NVP.PRIORITY_MODE, mode, ONYXKEYS.PRIORITY_MODE)
mode => NameValuePair.set(CONST.NVP.PRIORITY_MODE, mode, ONYXKEYS.NVP_PRIORITY_MODE)
}
items={Object.values(priorityModes)}
style={styles.picker}
Expand All @@ -80,6 +80,6 @@ PreferencesPage.displayName = 'PreferencesPage';

export default withOnyx({
priorityMode: {
key: ONYXKEYS.PRIORITY_MODE,
key: ONYXKEYS.NVP_PRIORITY_MODE,
},
})(PreferencesPage);
5 changes: 1 addition & 4 deletions tests/utils/TestHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ function fetchPersonalDetailsForTestUser(accountID, email, personalDetailsList)
accountID,
email,
personalDetailsList,
}))

// fetchTimezone
.mockImplementationOnce(() => Promise.resolve({}));
}));

fetchPersonalDetails();
return waitForPromisesToResolve();
Expand Down