From 759466a59078cb6a3c03db34c0ed18a6cd958eaa Mon Sep 17 00:00:00 2001
From: Alex Beaman <alexbeaman@expensify.com>
Date: Tue, 6 Jun 2023 18:00:40 -0400
Subject: [PATCH] Start personalDetails migration to *List

---
 src/ONYXKEYS.js                                  |  3 +++
 src/components/withCurrentUserPersonalDetails.js |  2 +-
 src/libs/DateUtils.js                            |  8 ++++----
 src/libs/PersonalDetailsUtils.js                 |  2 +-
 src/libs/actions/App.js                          | 16 +++++++---------
 tests/unit/DateUtilsTest.js                      |  4 ++--
 6 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js
index 41570519ab51..0b8e27463f05 100755
--- a/src/ONYXKEYS.js
+++ b/src/ONYXKEYS.js
@@ -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',
 
diff --git a/src/components/withCurrentUserPersonalDetails.js b/src/components/withCurrentUserPersonalDetails.js
index 52a822a5096a..60819a5f9ec4 100644
--- a/src/components/withCurrentUserPersonalDetails.js
+++ b/src/components/withCurrentUserPersonalDetails.js
@@ -64,7 +64,7 @@ export default function (WrappedComponent) {
 
     return withOnyx({
         personalDetails: {
-            key: ONYXKEYS.PERSONAL_DETAILS,
+            key: ONYXKEYS.PERSONAL_DETAILS_LIST,
         },
         session: {
             key: ONYXKEYS.SESSION,
diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js
index 7196a8f0a89e..6be627dc643d 100644
--- a/src/libs/DateUtils.js
+++ b/src/libs/DateUtils.js
@@ -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) => {
@@ -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);
     },
 });
 
diff --git a/src/libs/PersonalDetailsUtils.js b/src/libs/PersonalDetailsUtils.js
index 2f84e9db5e07..1cdddc136f7e 100644
--- a/src/libs/PersonalDetailsUtils.js
+++ b/src/libs/PersonalDetailsUtils.js
@@ -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)),
 });
 
diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js
index eccf2623f7f5..38638e22a464 100644
--- a/src/libs/actions/App.js
+++ b/src/libs/actions/App.js
@@ -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', '');
     },
 });
 
@@ -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];
     },
 });
 
@@ -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,
                         },
                     },
@@ -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,
                         },
                     },
diff --git a/tests/unit/DateUtilsTest.js b/tests/unit/DateUtilsTest.js
index cb1e8d839fa1..da2c9456e205 100644
--- a/tests/unit/DateUtilsTest.js
+++ b/tests/unit/DateUtilsTest.js
@@ -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();
