diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 0b8e27463f05..41570519ab51 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -45,9 +45,6 @@ export default { // Contains all the personalDetails the user has access to PERSONAL_DETAILS: 'personalDetails', - // Contains all the personalDetails the user has access to, keyed by accountID - PERSONAL_DETAILS_LIST: 'personalDetailsList', - // Contains all the private personal details of the user PRIVATE_PERSONAL_DETAILS: 'private_personalDetails', diff --git a/src/components/withCurrentUserPersonalDetails.js b/src/components/withCurrentUserPersonalDetails.js index 6c6cfe117cc9..52a822a5096a 100644 --- a/src/components/withCurrentUserPersonalDetails.js +++ b/src/components/withCurrentUserPersonalDetails.js @@ -36,7 +36,9 @@ export default function (WrappedComponent) { }; const WithCurrentUserPersonalDetails = (props) => { - const currentUserPersonalDetails = useMemo(() => props.personalDetails[props.session.accountID], [props.personalDetails, props.session.accountID]); + const currentUserEmail = props.session.email; + const accountID = props.session.accountID; + const currentUserPersonalDetails = useMemo(() => ({...props.personalDetails[currentUserEmail], accountID}), [props.personalDetails, currentUserEmail, accountID]); return ( { @@ -20,15 +20,15 @@ Onyx.connect({ return; } - currentAccountID = val.accountID; + currentUserEmail = val.email; }, }); let timezone = CONST.DEFAULT_TIME_ZONE; Onyx.connect({ - key: ONYXKEYS.PERSONAL_DETAILS_LIST, + key: ONYXKEYS.PERSONAL_DETAILS, callback: (val) => { - timezone = lodashGet(val, [currentAccountID, 'timezone'], CONST.DEFAULT_TIME_ZONE); + timezone = lodashGet(val, [currentUserEmail, 'timezone'], CONST.DEFAULT_TIME_ZONE); }, }); diff --git a/src/libs/PersonalDetailsUtils.js b/src/libs/PersonalDetailsUtils.js index ef6209e70c65..2f84e9db5e07 100644 --- a/src/libs/PersonalDetailsUtils.js +++ b/src/libs/PersonalDetailsUtils.js @@ -5,14 +5,14 @@ import * as Localize from './Localize'; let personalDetails = []; Onyx.connect({ - key: ONYXKEYS.PERSONAL_DETAILS_LIST, + key: ONYXKEYS.PERSONAL_DETAILS, callback: (val) => (personalDetails = _.values(val)), }); /** * Given a list of account IDs (as string) it will return an array of personal details objects. * @param {Array} accountIDs - Array of accountIDs - * @param {String} currentUserAccountID + * @param {Number} currentUserAccountID * @param {Boolean} shouldChangeUserDisplayName - It will replace the current user's personal detail object's displayName with 'You'. * @returns {Array} - Array of personal detail objects */ @@ -21,7 +21,7 @@ function getPersonalDetailsByIDs(accountIDs, currentUserAccountID, shouldChangeU _.each( _.filter(personalDetails, (detail) => accountIDs.includes(detail.accountID)), (detail) => { - if (shouldChangeUserDisplayName && currentUserAccountID === detail.accountID) { + if (shouldChangeUserDisplayName && currentUserAccountID.toString() === detail.accountID) { result.push({ ...detail, displayName: Localize.translateLocal('common.you'), diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index b3bae87fdfed..6a191690bbec 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -17,10 +17,12 @@ import getCurrentUrl from '../Navigation/currentUrl'; import * as Session from './Session'; let currentUserAccountID; +let currentUserEmail; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (val) => { currentUserAccountID = lodashGet(val, 'accountID', ''); + currentUserEmail = lodashGet(val, 'email', ''); }, }); @@ -33,13 +35,13 @@ Onyx.connect({ let myPersonalDetails; Onyx.connect({ - key: ONYXKEYS.PERSONAL_DETAILS_LIST, + key: ONYXKEYS.PERSONAL_DETAILS, callback: (val) => { - if (!val || !currentUserAccountID) { + if (!val || !currentUserEmail) { return; } - myPersonalDetails = val[currentUserAccountID]; + myPersonalDetails = val[currentUserEmail]; }, }); @@ -292,9 +294,9 @@ function openProfile() { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, + key: ONYXKEYS.PERSONAL_DETAILS, value: { - [currentUserAccountID]: { + [currentUserEmail]: { timezone: newTimezoneData, }, }, @@ -303,9 +305,9 @@ function openProfile() { failureData: [ { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, + key: ONYXKEYS.PERSONAL_DETAILS, value: { - [currentUserAccountID]: { + [currentUserEmail]: { timezone: oldTimezoneData, }, }, diff --git a/tests/unit/DateUtilsTest.js b/tests/unit/DateUtilsTest.js index da2c9456e205..cb1e8d839fa1 100644 --- a/tests/unit/DateUtilsTest.js +++ b/tests/unit/DateUtilsTest.js @@ -12,8 +12,8 @@ describe('DateUtils', () => { Onyx.init({ keys: ONYXKEYS, initialKeyStates: { - [ONYXKEYS.SESSION]: {accountID: 999}, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: {999: {timezone: {selected: 'Etc/UTC'}}}, + [ONYXKEYS.SESSION]: {email: 'current@user.com'}, + [ONYXKEYS.PERSONAL_DETAILS]: {'current@user.com': {timezone: {selected: 'Etc/UTC'}}}, }, }); return waitForPromisesToResolve();