From d4d97c5cf76faf0d743ff2e55dc0b0214d0336b8 Mon Sep 17 00:00:00 2001
From: Yuwen Memon <yuwen@expensify.com>
Date: Wed, 28 Jun 2023 11:05:55 -0700
Subject: [PATCH 1/2] Make sure we call OpenProfile action even if we're
 accessing the page directly

---
 src/libs/actions/App.js                   | 18 ++----------------
 src/libs/actions/IOU.js                   |  6 ++++++
 src/pages/settings/InitialSettingsPage.js |  3 +--
 src/pages/settings/Profile/ProfilePage.js |  7 ++++++-
 4 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js
index 38638e22a464..d4012829b90c 100644
--- a/src/libs/actions/App.js
+++ b/src/libs/actions/App.js
@@ -31,18 +31,6 @@ Onyx.connect({
     initWithStoredValues: false,
 });
 
-let myPersonalDetails;
-Onyx.connect({
-    key: ONYXKEYS.PERSONAL_DETAILS_LIST,
-    callback: (val) => {
-        if (!val || !currentUserAccountID) {
-            return;
-        }
-
-        myPersonalDetails = val[currentUserAccountID];
-    },
-});
-
 let allPolicies = [];
 Onyx.connect({
     key: ONYXKEYS.COLLECTION.POLICY,
@@ -267,8 +255,8 @@ function setUpPoliciesAndNavigate(session) {
     }
 }
 
-function openProfile() {
-    const oldTimezoneData = myPersonalDetails.timezone || {};
+function openProfile(personalDetails) {
+    const oldTimezoneData = personalDetails.timezone || {};
     let newTimezoneData = oldTimezoneData;
 
     if (lodashGet(oldTimezoneData, 'automatic', true)) {
@@ -308,8 +296,6 @@ function openProfile() {
             ],
         },
     );
-
-    Navigation.navigate(ROUTES.SETTINGS_PROFILE);
 }
 
 export {setLocale, setLocaleAndNavigate, setSidebarLoaded, setUpPoliciesAndNavigate, openProfile, openApp, reconnectApp, confirmReadyToOpenApp};
diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js
index 1e3a297f08da..dac3b07515a0 100644
--- a/src/libs/actions/IOU.js
+++ b/src/libs/actions/IOU.js
@@ -1070,6 +1070,11 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
         optimisticData.push(optimisticPersonalDetailListData);
     }
 
+    let reportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, optimisticIOUReport.reportID);
+    if (!reportPreviewAction) {
+        reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport.reportID, optimisticIOUReport.reportID);
+    }
+
     return {
         params: {
             iouReportID: optimisticIOUReport.reportID,
@@ -1079,6 +1084,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
             transactionID: optimisticTransaction.transactionID,
             newIOUReportDetails,
             createdReportActionID: isNewChat ? optimisticCreatedAction.reportActionID : 0,
+            reportPreviewReportActionID: reportPreviewAction.reportActionID,
         },
         optimisticData,
         successData,
diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js
index b7364ce623fa..97d013f31084 100755
--- a/src/pages/settings/InitialSettingsPage.js
+++ b/src/pages/settings/InitialSettingsPage.js
@@ -21,7 +21,6 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize
 import compose from '../../libs/compose';
 import CONST from '../../CONST';
 import Permissions from '../../libs/Permissions';
-import * as App from '../../libs/actions/App';
 import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../components/withCurrentUserPersonalDetails';
 import * as PaymentMethods from '../../libs/actions/PaymentMethods';
 import bankAccountPropTypes from '../../components/bankAccountPropTypes';
@@ -200,7 +199,7 @@ class InitialSettingsPage extends React.Component {
                 translationKey: 'common.profile',
                 icon: Expensicons.Profile,
                 action: () => {
-                    App.openProfile();
+                    Navigation.navigate(ROUTES.SETTINGS_PROFILE);
                 },
                 brickRoadIndicator: profileBrickRoadIndicator,
             },
diff --git a/src/pages/settings/Profile/ProfilePage.js b/src/pages/settings/Profile/ProfilePage.js
index 1fd1e585648d..07db3d0cdffb 100755
--- a/src/pages/settings/Profile/ProfilePage.js
+++ b/src/pages/settings/Profile/ProfilePage.js
@@ -1,5 +1,5 @@
 import lodashGet from 'lodash/get';
-import React from 'react';
+import React, {useEffect} from 'react';
 import {View} from 'react-native';
 import PropTypes from 'prop-types';
 import {withOnyx} from 'react-native-onyx';
@@ -23,6 +23,7 @@ import * as Expensicons from '../../../components/Icon/Expensicons';
 import ONYXKEYS from '../../../ONYXKEYS';
 import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
 import userPropTypes from '../userPropTypes';
+import * as App from '../../../libs/actions/App';
 
 const propTypes = {
     /* Onyx Props */
@@ -84,6 +85,10 @@ function ProfilePage(props) {
         },
     ];
 
+    useEffect(() => {
+        App.openProfile(props.currentUserPersonalDetails);
+    }, [props.currentUserPersonalDetails]);
+
     return (
         <ScreenWrapper includeSafeAreaPaddingBottom={false}>
             <HeaderWithBackButton

From b895d5efe9318b9dbc61a32bf958c207b0cd2040 Mon Sep 17 00:00:00 2001
From: Yuwen Memon <yuwen@expensify.com>
Date: Thu, 29 Jun 2023 10:21:10 -0700
Subject: [PATCH 2/2] Remove mixed up code

---
 src/libs/actions/IOU.js | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js
index dac3b07515a0..1e3a297f08da 100644
--- a/src/libs/actions/IOU.js
+++ b/src/libs/actions/IOU.js
@@ -1070,11 +1070,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
         optimisticData.push(optimisticPersonalDetailListData);
     }
 
-    let reportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, optimisticIOUReport.reportID);
-    if (!reportPreviewAction) {
-        reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport.reportID, optimisticIOUReport.reportID);
-    }
-
     return {
         params: {
             iouReportID: optimisticIOUReport.reportID,
@@ -1084,7 +1079,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
             transactionID: optimisticTransaction.transactionID,
             newIOUReportDetails,
             createdReportActionID: isNewChat ? optimisticCreatedAction.reportActionID : 0,
-            reportPreviewReportActionID: reportPreviewAction.reportActionID,
         },
         optimisticData,
         successData,
