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

Start personalDetails migration to *List #20323

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
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ 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
2 changes: 1 addition & 1 deletion src/components/withCurrentUserPersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function (WrappedComponent) {

return withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
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 currentUserEmail;
let currentUserAccountID;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
Expand All @@ -20,15 +20,15 @@ Onyx.connect({
return;
}

currentUserEmail = val.email;
currentUserAccountID = val.accountID;
},
});

let timezone = CONST.DEFAULT_TIME_ZONE;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
timezone = lodashGet(val, [currentUserEmail, 'timezone'], CONST.DEFAULT_TIME_ZONE);
timezone = lodashGet(val, [currentUserAccountID, 'timezone'], CONST.DEFAULT_TIME_ZONE);
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/libs/PersonalDetailsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Localize from './Localize';

let personalDetails = [];
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (personalDetails = _.values(val)),
});

Expand Down
16 changes: 7 additions & 9 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ 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 @@ -35,13 +33,13 @@ Onyx.connect({

let myPersonalDetails;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
if (!val || !currentUserEmail) {
if (!val || !currentUserAccountID) {
return;
}

myPersonalDetails = val[currentUserEmail];
myPersonalDetails = val[currentUserAccountID];
},
});

Expand Down Expand Up @@ -289,9 +287,9 @@ function openProfile() {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserEmail]: {
[currentUserAccountID]: {
timezone: newTimezoneData,
},
},
Expand All @@ -300,9 +298,9 @@ function openProfile() {
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserEmail]: {
[currentUserAccountID]: {
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]: {email: 'current@user.com'},
[ONYXKEYS.PERSONAL_DETAILS]: {'current@user.com': {timezone: {selected: 'Etc/UTC'}}},
[ONYXKEYS.SESSION]: {accountID: 999},
[ONYXKEYS.PERSONAL_DETAILS_LIST]: {999: {timezone: {selected: 'Etc/UTC'}}},
},
});
return waitForPromisesToResolve();
Expand Down