Skip to content

Commit

Permalink
Merge pull request #20220 from Expensify/Rory-RevertNewCurrentUserPer…
Browse files Browse the repository at this point in the history
…sonalDetailsStuff

Revert PERSONAL_DETAILS_LIST Onyx changes
  • Loading branch information
roryabraham authored Jun 5, 2023
2 parents 27ee38b + f5a0029 commit e97803a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
3 changes: 0 additions & 3 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
6 changes: 4 additions & 2 deletions src/components/withCurrentUserPersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
Expand All @@ -62,7 +64,7 @@ export default function (WrappedComponent) {

return withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
key: ONYXKEYS.PERSONAL_DETAILS,
},
session: {
key: ONYXKEYS.SESSION,
Expand Down
8 changes: 4 additions & 4 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CONST from '../CONST';
import * as Localize from './Localize';
import * as CurrentDate from './actions/CurrentDate';

let currentAccountID;
let currentUserEmail;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
Expand All @@ -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);
},
});

Expand Down
6 changes: 3 additions & 3 deletions src/libs/PersonalDetailsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} 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
*/
Expand All @@ -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'),
Expand Down
16 changes: 9 additions & 7 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
},
});

Expand All @@ -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];
},
});

Expand Down Expand Up @@ -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,
},
},
Expand All @@ -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,
},
},
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/DateUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'},
[ONYXKEYS.PERSONAL_DETAILS]: {'[email protected]': {timezone: {selected: 'Etc/UTC'}}},
},
});
return waitForPromisesToResolve();
Expand Down

0 comments on commit e97803a

Please sign in to comment.