From 8f7ab26d9744812b97f0af1a8e91579eac436fc2 Mon Sep 17 00:00:00 2001
From: Andrew Rosiclair <arosiclair@expensify.com>
Date: Tue, 15 Aug 2023 13:22:47 -0400
Subject: [PATCH 1/7] add distance menu item

---
 src/components/ReportActionItem/MoneyRequestView.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js
index b01226df0d35..5386038090da 100644
--- a/src/components/ReportActionItem/MoneyRequestView.js
+++ b/src/components/ReportActionItem/MoneyRequestView.js
@@ -94,6 +94,8 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
         receiptUris = ReceiptUtils.getThumbnailAndImageURIs(transaction.receipt.source, transaction.filename);
     }
 
+    const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
+
     return (
         <View>
             <View style={[StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth), StyleUtils.getMinimumHeight(CONST.EMPTY_STATE_BACKGROUND.MONEY_REPORT.MIN_HEIGHT)]}>
@@ -128,6 +130,15 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
                 shouldShowRightIcon={canEdit}
                 onPress={() => Navigation.navigate(ROUTES.getEditRequestRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.DATE))}
             />
+            {isDistanceRequest && (
+                <MenuItemWithTopDescription
+                    description={translate('tabSelector.distance')}
+                    title="123 miles @ $456 / mile"
+                    disabled={isSettled || !canEdit}
+                    shouldShowRightIcon={canEdit}
+                    onPress={() => {}}
+                />
+            )}
             {shouldShowHorizontalRule && <View style={styles.reportHorizontalRule} />}
         </View>
     );

From 5c64db923e97377357eab63880aa12a501452911 Mon Sep 17 00:00:00 2001
From: Andrew Rosiclair <arosiclair@expensify.com>
Date: Tue, 15 Aug 2023 13:26:46 -0400
Subject: [PATCH 2/7] get custom unit and mileage rate and use distance text
 stub

---
 .../ReportActionItem/MoneyRequestView.js      |  5 ++++-
 src/libs/PolicyUtils.js                       | 20 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js
index 5386038090da..abbe30ab895f 100644
--- a/src/components/ReportActionItem/MoneyRequestView.js
+++ b/src/components/ReportActionItem/MoneyRequestView.js
@@ -23,6 +23,7 @@ import * as CurrencyUtils from '../../libs/CurrencyUtils';
 import EmptyStateBackgroundImage from '../../../assets/images/empty-state_background-fade.png';
 import useLocalize from '../../hooks/useLocalize';
 import * as TransactionUtils from '../../libs/TransactionUtils';
+import * as PolicyUtils from '../../libs/PolicyUtils';
 import * as ReceiptUtils from '../../libs/ReceiptUtils';
 import withLocalize from '../withLocalize';
 import useWindowDimensions from '../../hooks/useWindowDimensions';
@@ -95,6 +96,8 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
     }
 
     const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
+    const distanceCustomUnit = PolicyUtils.getDistanceCustomUnit(policy);
+    const mileageRate = PolicyUtils.getDefaultMileageRate(distanceCustomUnit);
 
     return (
         <View>
@@ -133,7 +136,7 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
             {isDistanceRequest && (
                 <MenuItemWithTopDescription
                     description={translate('tabSelector.distance')}
-                    title="123 miles @ $456 / mile"
+                    title={PolicyUtils.getDistanceText(transaction, distanceCustomUnit, mileageRate)}
                     disabled={isSettled || !canEdit}
                     shouldShowRightIcon={canEdit}
                     onPress={() => {}}
diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js
index 582271d6610e..7be02703415d 100644
--- a/src/libs/PolicyUtils.js
+++ b/src/libs/PolicyUtils.js
@@ -166,6 +166,23 @@ function getIneligibleInvitees(policyMembers, personalDetails) {
     return memberEmailsToExclude;
 }
 
+function getDistanceCustomUnit(policy) {
+    const customUnits = _.values(policy.customUnits);
+    return _.find(customUnits, (customUnit) => customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE);
+}
+
+function getDefaultMileageRate(customUnit) {
+    if (!customUnit) {
+        return 0;
+    }
+
+    return _.find(customUnit.rates, (rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE);
+}
+
+function getDistanceText(transaction, customUnit, mileageRate) {
+    return '123 miles @ $456 / mile';
+}
+
 export {
     getActivePolicies,
     hasPolicyMemberError,
@@ -179,4 +196,7 @@ export {
     isPolicyAdmin,
     getMemberAccountIDsForWorkspace,
     getIneligibleInvitees,
+    getDistanceCustomUnit,
+    getDefaultMileageRate,
+    getDistanceText,
 };

From 8de53ea30399e1f4de378cf5111f566f562cf850 Mon Sep 17 00:00:00 2001
From: Andrew Rosiclair <arosiclair@expensify.com>
Date: Tue, 15 Aug 2023 13:35:59 -0400
Subject: [PATCH 3/7] add isDistanceRequest stub

---
 src/libs/TransactionUtils.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js
index 48892a69cc01..92f9b74e1eb0 100644
--- a/src/libs/TransactionUtils.js
+++ b/src/libs/TransactionUtils.js
@@ -167,4 +167,8 @@ function getCreated(transaction) {
     return format(new Date(lodashGet(transaction, 'created', '')), CONST.DATE.FNS_FORMAT_STRING);
 }
 
-export {buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated};
+function isDistanceRequest(transaction) {
+    return true;
+}
+
+export {buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated, isDistanceRequest};

From acdf45df70559a71afdf6799a4ebc1eba008efb2 Mon Sep 17 00:00:00 2001
From: Andrew Rosiclair <arosiclair@expensify.com>
Date: Tue, 15 Aug 2023 14:15:46 -0400
Subject: [PATCH 4/7] use transaction merchant instead of recomputing the
 distance text

---
 .../ReportActionItem/MoneyRequestView.js      |  5 +----
 src/libs/PolicyUtils.js                       | 20 -------------------
 2 files changed, 1 insertion(+), 24 deletions(-)

diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js
index abbe30ab895f..4db4fea47472 100644
--- a/src/components/ReportActionItem/MoneyRequestView.js
+++ b/src/components/ReportActionItem/MoneyRequestView.js
@@ -23,7 +23,6 @@ import * as CurrencyUtils from '../../libs/CurrencyUtils';
 import EmptyStateBackgroundImage from '../../../assets/images/empty-state_background-fade.png';
 import useLocalize from '../../hooks/useLocalize';
 import * as TransactionUtils from '../../libs/TransactionUtils';
-import * as PolicyUtils from '../../libs/PolicyUtils';
 import * as ReceiptUtils from '../../libs/ReceiptUtils';
 import withLocalize from '../withLocalize';
 import useWindowDimensions from '../../hooks/useWindowDimensions';
@@ -96,8 +95,6 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
     }
 
     const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
-    const distanceCustomUnit = PolicyUtils.getDistanceCustomUnit(policy);
-    const mileageRate = PolicyUtils.getDefaultMileageRate(distanceCustomUnit);
 
     return (
         <View>
@@ -136,7 +133,7 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
             {isDistanceRequest && (
                 <MenuItemWithTopDescription
                     description={translate('tabSelector.distance')}
-                    title={PolicyUtils.getDistanceText(transaction, distanceCustomUnit, mileageRate)}
+                    title={transaction.merchant}
                     disabled={isSettled || !canEdit}
                     shouldShowRightIcon={canEdit}
                     onPress={() => {}}
diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js
index 7be02703415d..582271d6610e 100644
--- a/src/libs/PolicyUtils.js
+++ b/src/libs/PolicyUtils.js
@@ -166,23 +166,6 @@ function getIneligibleInvitees(policyMembers, personalDetails) {
     return memberEmailsToExclude;
 }
 
-function getDistanceCustomUnit(policy) {
-    const customUnits = _.values(policy.customUnits);
-    return _.find(customUnits, (customUnit) => customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE);
-}
-
-function getDefaultMileageRate(customUnit) {
-    if (!customUnit) {
-        return 0;
-    }
-
-    return _.find(customUnit.rates, (rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE);
-}
-
-function getDistanceText(transaction, customUnit, mileageRate) {
-    return '123 miles @ $456 / mile';
-}
-
 export {
     getActivePolicies,
     hasPolicyMemberError,
@@ -196,7 +179,4 @@ export {
     isPolicyAdmin,
     getMemberAccountIDsForWorkspace,
     getIneligibleInvitees,
-    getDistanceCustomUnit,
-    getDefaultMileageRate,
-    getDistanceText,
 };

From 35d08c4a7cbc7700d19784a4c978a562a93779fc Mon Sep 17 00:00:00 2001
From: Andrew Rosiclair <arosiclair@expensify.com>
Date: Tue, 22 Aug 2023 10:27:19 -0400
Subject: [PATCH 5/7] use existing merchant menu item for distance

---
 src/components/ReportActionItem/MoneyRequestView.js | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js
index 7c4a53dfa5f7..ac7c0784c499 100644
--- a/src/components/ReportActionItem/MoneyRequestView.js
+++ b/src/components/ReportActionItem/MoneyRequestView.js
@@ -164,21 +164,12 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
             </OfflineWithFeedback>
             <OfflineWithFeedback pendingAction={lodashGet(transaction, 'pendingFields.merchant') || lodashGet(transaction, 'pendingAction')}>
                 <MenuItemWithTopDescription
-                    description={translate('common.merchant')}
+                    description={isDistanceRequest ? translate('tabSelector.distance') : translate('common.merchant')}
                     title={transactionMerchant}
                     shouldShowRightIcon={false}
                     disabled
                 />
             </OfflineWithFeedback>
-            {isDistanceRequest && (
-                <MenuItemWithTopDescription
-                    description={translate('tabSelector.distance')}
-                    title={transaction.merchant}
-                    disabled={isSettled || !canEdit}
-                    shouldShowRightIcon={canEdit}
-                    onPress={() => {}}
-                />
-            )}
             {shouldShowHorizontalRule && <View style={styles.reportHorizontalRule} />}
         </View>
     );

From 6c8815bd0d94f07a3b05ad83cf5dc0b9f304e460 Mon Sep 17 00:00:00 2001
From: Andrew Rosiclair <arosiclair@expensify.com>
Date: Tue, 22 Aug 2023 10:31:22 -0400
Subject: [PATCH 6/7] add isDistanceRequest implementation

---
 src/CONST.js                 |  5 +++++
 src/libs/TransactionUtils.js | 11 ++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/CONST.js b/src/CONST.js
index 901d2f7f4241..384f7a3e5e12 100755
--- a/src/CONST.js
+++ b/src/CONST.js
@@ -661,6 +661,11 @@ const CONST = {
         DARK: 'dark',
         SYSTEM: 'system',
     },
+    TRANSACTION: {
+        TYPE: {
+            CUSTOM_UNIT: 'customUnit',
+        },
+    },
     JSON_CODE: {
         SUCCESS: 200,
         BAD_REQUEST: 400,
diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js
index d6083e5d771c..c4f802e0aa72 100644
--- a/src/libs/TransactionUtils.js
+++ b/src/libs/TransactionUtils.js
@@ -243,8 +243,17 @@ function isReceiptBeingScanned(transaction) {
     return transaction.receipt.state === CONST.IOU.RECEIPT_STATE.SCANREADY || transaction.receipt.state === CONST.IOU.RECEIPT_STATE.SCANNING;
 }
 
+/**
+ * @param {Object} transaction
+ * @param {String} transaction.type
+ * @param {Object} [transaction.customUnit]
+ * @param {String} [transaction.customUnit.name]
+ * @returns {Boolean}
+ */
 function isDistanceRequest(transaction) {
-    return true;
+    const type = lodashGet(transaction, 'comment.type');
+    const customUnitName = lodashGet(transaction, 'comment.customUnit.name');
+    return type === CONST.TRANSACTION.TYPE.CUSTOM_UNIT && customUnitName === CONST.CUSTOM_UNITS.NAME_DISTANCE;
 }
 
 export {

From afd324052baeafc3463564b4f0f6ae2f4021c251 Mon Sep 17 00:00:00 2001
From: Andrew Rosiclair <arosiclair@expensify.com>
Date: Tue, 22 Aug 2023 11:40:17 -0400
Subject: [PATCH 7/7] remove disabled for merchant/distance item

---
 src/components/ReportActionItem/MoneyRequestView.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js
index ac7c0784c499..85fa14987d6b 100644
--- a/src/components/ReportActionItem/MoneyRequestView.js
+++ b/src/components/ReportActionItem/MoneyRequestView.js
@@ -167,7 +167,6 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
                     description={isDistanceRequest ? translate('tabSelector.distance') : translate('common.merchant')}
                     title={transactionMerchant}
                     shouldShowRightIcon={false}
-                    disabled
                 />
             </OfflineWithFeedback>
             {shouldShowHorizontalRule && <View style={styles.reportHorizontalRule} />}
