From 32256506be6db98e5699824bc1262e219a036be1 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 13:55:27 -0600 Subject: [PATCH 01/17] Remove unused prop --- src/components/ReportActionItem/MoneyRequestPreview.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index e5a53be6c46a..85fb952a2959 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -100,9 +100,6 @@ const propTypes = { /** Information about the user accepting the terms for payments */ walletTerms: walletTermsPropTypes, - /** Pending action, if any */ - pendingAction: PropTypes.oneOf(_.values(CONST.RED_BRICK_ROAD_PENDING_ACTION)), - /** Whether or not an IOU report contains money requests in a different currency * that are either created or cancelled offline, and thus haven't been converted to the report's currency yet */ @@ -119,7 +116,6 @@ const defaultProps = { checkIfContextMenuActive: () => {}, containerStyles: [], walletTerms: {}, - pendingAction: null, isHovered: false, personalDetails: {}, session: { @@ -197,7 +193,6 @@ function MoneyRequestPreview(props) { const childContainer = ( { PaymentMethods.clearWalletTermsError(); From 648c9c2e1c4beee93537383ab7d076c663acdd64 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 14:00:08 -0600 Subject: [PATCH 02/17] Add transaction subscription --- src/components/ReportActionItem/MoneyRequestPreview.js | 7 +++++++ src/pages/home/report/reportActionFragmentPropTypes.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 85fb952a2959..85311b91073e 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -91,6 +91,9 @@ const propTypes = { }), ), + /** The transaction attached to the action.message.iouTransactionID */ + transaction: PropTypes.any, + /** Session info for the currently logged in user. */ session: PropTypes.shape({ /** Currently logged in user email */ @@ -121,6 +124,7 @@ const defaultProps = { session: { email: null, }, + transaction: null, shouldShowPendingConversionMessage: false, }; @@ -311,6 +315,9 @@ export default compose( session: { key: ONYXKEYS.SESSION, }, + transaction: { + key: ({action}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${(action && action.message && action.message.iouTransactionID) || 0}`, + }, walletTerms: { key: ONYXKEYS.WALLET_TERMS, }, diff --git a/src/pages/home/report/reportActionFragmentPropTypes.js b/src/pages/home/report/reportActionFragmentPropTypes.js index 5d2e3b951a1d..2949813dcebd 100644 --- a/src/pages/home/report/reportActionFragmentPropTypes.js +++ b/src/pages/home/report/reportActionFragmentPropTypes.js @@ -29,4 +29,7 @@ export default PropTypes.shape({ /** Fragment edited flag */ isEdited: PropTypes.bool, + + /** A possible IOU transaction ID */ + iouTransactionID: PropTypes.int, }); From d91b6947683dc96e056c2d45e19e2935e740254f Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 14:12:19 -0600 Subject: [PATCH 03/17] Add a method to determine transaction type --- src/CONST.js | 5 +++++ src/libs/TransactionUtils.js | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index cc5d63be0373..0319ac4fad71 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -639,6 +639,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 48892a69cc01..8a11f536b20a 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -167,4 +167,15 @@ function getCreated(transaction) { return format(new Date(lodashGet(transaction, 'created', '')), CONST.DATE.FNS_FORMAT_STRING); } -export {buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated}; +/** + * @param {Object} transaction + * @param {String} transaction.type + * @param {Object} [transaction.customUnit] + * @param {String} [transaction.customUnit.name] + * @returns {Boolean} + */ +function isDistanceRequest(transaction) { + return transaction && transaction.type === CONST.TRANSACTION.TYPE.CUSTOM_UNIT && transaction.customUnit && transaction.customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE; +} + +export {buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated, isDistanceRequest}; From 846176339f557a4cc4719c15a39c8538037c881d Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 14:18:47 -0600 Subject: [PATCH 04/17] Add method for getting a receipt URL --- src/libs/ReceiptUtils.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libs/ReceiptUtils.js b/src/libs/ReceiptUtils.js index 635537226815..c9c6fcffa3f0 100644 --- a/src/libs/ReceiptUtils.js +++ b/src/libs/ReceiptUtils.js @@ -9,6 +9,7 @@ import ReceiptHTML from '../../assets/images/receipt-html.png'; import ReceiptDoc from '../../assets/images/receipt-doc.png'; import ReceiptGeneric from '../../assets/images/receipt-generic.png'; import ReceiptSVG from '../../assets/images/receipt-svg.png'; +import CONFIG from '../CONFIG'; function validateReceipt(file) { const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(file, 'name', '')); @@ -68,4 +69,13 @@ function isBeingScanned(receipt) { return receipt.state === CONST.IOU.RECEIPT_STATE.SCANREADY || receipt.state === CONST.IOU.RECEIPT_STATE.SCANNING; } -export {validateReceipt, getThumbnailAndImageURIs, isBeingScanned}; +/** + * Returns the URL of a receipt given a filename + * @param {String} filename + * @returns {String} + */ +function getURL(filename) { + return `${CONFIG.EXPENSIFY.EXPENSIFY_URL}receipts/${filename}`; +} + +export {validateReceipt, getThumbnailAndImageURIs, getURL, isBeingScanned}; From 8600f5c4aeae21e11f6b080fdb4af04eefbc923d Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 14:32:13 -0600 Subject: [PATCH 05/17] Display header and amount --- .../ReportActionItem/MoneyRequestPreview.js | 31 +++++++++++++++---- .../report/reportActionFragmentPropTypes.js | 3 -- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 85311b91073e..06bbcc2b0e57 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -92,7 +92,18 @@ const propTypes = { ), /** The transaction attached to the action.message.iouTransactionID */ - transaction: PropTypes.any, + transaction: PropTypes.shape({ + /** The type of transaction */ + type: PropTypes.string, + + /** Custom units attached to the transaction */ + customUnits: PropTypes.arrayOf( + PropTypes.shape({ + /** The name of the custom unit */ + name: PropTypes.string, + }), + ), + }), /** Session info for the currently logged in user. */ session: PropTypes.shape({ @@ -124,7 +135,7 @@ const defaultProps = { session: { email: null, }, - transaction: null, + transaction: {}, shouldShowPendingConversionMessage: false, }; @@ -147,9 +158,9 @@ function MoneyRequestPreview(props) { const requestCurrency = moneyRequestAction.currency; const requestComment = moneyRequestAction.comment.trim(); - const transaction = ReportActionUtils.getTransaction(props.action); - const hasReceipt = TransactionUtils.hasReceipt(transaction); + const hasReceipt = TransactionUtils.hasReceipt(props.transaction); const isScanning = !ReportActionUtils.hasReadyMoneyRequests(props.action); + const isDistanceRequest = props.transaction && TransactionUtils.isDistanceRequest(props.transaction); const getSettledMessage = () => { switch (lodashGet(props.action, 'originalMessage.paymentType', '')) { @@ -169,6 +180,10 @@ function MoneyRequestPreview(props) { }; const getPreviewHeaderText = () => { + if (isDistanceRequest) { + return props.translate('tabSelector.distance'); + } + if (isScanning) { return props.translate('common.receipt'); } @@ -187,6 +202,10 @@ function MoneyRequestPreview(props) { }; const getDisplayAmountText = () => { + if (isDistanceRequest) { + return TransactionUtils.getAmount(props.transaction); + } + if (isScanning) { return props.translate('iou.receiptScanning'); } @@ -208,7 +227,7 @@ function MoneyRequestPreview(props) { {hasReceipt && ( `${ONYXKEYS.COLLECTION.TRANSACTION}${(action && action.message && action.message.iouTransactionID) || 0}`, + key: ({action}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${(action && action.originalMessage && action.originalMessage.IOUTransactionID) || 0}`, }, walletTerms: { key: ONYXKEYS.WALLET_TERMS, diff --git a/src/pages/home/report/reportActionFragmentPropTypes.js b/src/pages/home/report/reportActionFragmentPropTypes.js index 2949813dcebd..5d2e3b951a1d 100644 --- a/src/pages/home/report/reportActionFragmentPropTypes.js +++ b/src/pages/home/report/reportActionFragmentPropTypes.js @@ -29,7 +29,4 @@ export default PropTypes.shape({ /** Fragment edited flag */ isEdited: PropTypes.bool, - - /** A possible IOU transaction ID */ - iouTransactionID: PropTypes.int, }); From 613e662a74020291191d14a69f66b35b1b9726d2 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 14:33:30 -0600 Subject: [PATCH 06/17] Remove duplicate method --- src/libs/TransactionUtils.js | 26 +------------------------- src/pages/EditRequestPage.js | 2 +- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 8a11f536b20a..f7cdd3168f27 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -1,24 +1,10 @@ -import Onyx from 'react-native-onyx'; import {format} from 'date-fns'; import lodashGet from 'lodash/get'; import _ from 'underscore'; import CONST from '../CONST'; -import ONYXKEYS from '../ONYXKEYS'; import DateUtils from './DateUtils'; import * as NumberUtils from './NumberUtils'; -let allTransactions = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.TRANSACTION, - waitForCollectionCallback: true, - callback: (val) => { - if (!val) { - return; - } - allTransactions = val; - }, -}); - /** * Optimistically generate a transaction. * @@ -101,16 +87,6 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep return updatedTransaction; } -/** - * Retrieve the particular transaction object given its ID. - * - * @param {String} transactionID - * @returns {Object} - */ -function getTransaction(transactionID) { - return lodashGet(allTransactions, `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {}); -} - /** * Return the comment field (referred to as description in the App) from the transaction. * The comment does not have its modifiedComment counterpart. @@ -178,4 +154,4 @@ function isDistanceRequest(transaction) { return transaction && transaction.type === CONST.TRANSACTION.TYPE.CUSTOM_UNIT && transaction.customUnit && transaction.customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE; } -export {buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated, isDistanceRequest}; +export {buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, getDescription, getAmount, getCurrency, getCreated, isDistanceRequest}; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 971ad056ae7e..941a560591c2 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -39,7 +39,7 @@ const defaultProps = { function EditRequestPage({report, route}) { const transactionID = lodashGet(ReportActionsUtils.getParentReportAction(report), 'originalMessage.IOUTransactionID', ''); - const transaction = TransactionUtils.getTransaction(transactionID); + const transaction = ReportActionsUtils.getTransaction(transactionID); const transactionDescription = TransactionUtils.getDescription(transaction); const transactionAmount = TransactionUtils.getAmount(transaction, ReportUtils.isExpenseReport(ReportUtils.getParentReport(report))); const transactionCurrency = TransactionUtils.getCurrency(transaction); From f1a0e8efd08570566f96cae03efaa4e6dc8df4c4 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 14:37:06 -0600 Subject: [PATCH 07/17] Use the right description --- .../ReportActionItem/MoneyRequestPreview.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 06bbcc2b0e57..ebe210986460 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -93,6 +93,9 @@ const propTypes = { /** The transaction attached to the action.message.iouTransactionID */ transaction: PropTypes.shape({ + /** The name of the transaction merchant */ + merchant: PropTypes.string, + /** The type of transaction */ type: PropTypes.string, @@ -156,12 +159,17 @@ function MoneyRequestPreview(props) { const requestAmount = moneyRequestAction.amount; const requestCurrency = moneyRequestAction.currency; - const requestComment = moneyRequestAction.comment.trim(); + let description = moneyRequestAction.comment.trim(); const hasReceipt = TransactionUtils.hasReceipt(props.transaction); const isScanning = !ReportActionUtils.hasReadyMoneyRequests(props.action); const isDistanceRequest = props.transaction && TransactionUtils.isDistanceRequest(props.transaction); + // On a distance request the merchange of the transaction will be used for the description since that's where it's stored in the database + if (isDistanceRequest) { + description = props.transaction.merchant; + } + const getSettledMessage = () => { switch (lodashGet(props.action, 'originalMessage.paymentType', '')) { case CONST.IOU.PAYMENT_TYPE.PAYPAL_ME: @@ -284,7 +292,7 @@ function MoneyRequestPreview(props) { {!isCurrentUserManager && props.shouldShowPendingConversionMessage && ( {props.translate('iou.pendingConversionMessage')} )} - {!_.isEmpty(requestComment) && {requestComment}} + {!_.isEmpty(description) && {description}} {props.isBillSplit && !_.isEmpty(participantAccountIDs) && ( From 58d7fe245b5249e4bc8285a832017bcb42531a84 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 15:17:00 -0600 Subject: [PATCH 08/17] Add receipt image component --- src/components/ReportActionItem/MoneyRequestPreview.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index ebe210986460..ceffcafa89e1 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -93,6 +93,9 @@ const propTypes = { /** The transaction attached to the action.message.iouTransactionID */ transaction: PropTypes.shape({ + /** The name of the file for the receipt image. This is just the filename and doesn't come with any kind of a path */ + filename: PropTypes.string, + /** The name of the transaction merchant */ merchant: PropTypes.string, @@ -241,6 +244,8 @@ function MoneyRequestPreview(props) { hoverStyle={isScanning ? styles.moneyRequestPreviewBoxHover : undefined} /> )} + + {isDistanceRequest && } From d4b812ee3a250c8d379de58f348dfc1a6e6b8247 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 15 Aug 2023 20:51:16 -0600 Subject: [PATCH 09/17] Properly format currency and images --- .../ReportActionItem/MoneyRequestPreview.js | 4 ++-- src/libs/ReceiptUtils.js | 11 +---------- src/libs/TransactionUtils.js | 4 +++- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index ceffcafa89e1..0c111f6809c4 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -214,7 +214,7 @@ function MoneyRequestPreview(props) { const getDisplayAmountText = () => { if (isDistanceRequest) { - return TransactionUtils.getAmount(props.transaction); + return CurrencyUtils.convertToDisplayString(TransactionUtils.getAmount(props.transaction), props.transaction.currency); } if (isScanning) { @@ -245,7 +245,7 @@ function MoneyRequestPreview(props) { /> )} - {isDistanceRequest && } + {isDistanceRequest && } diff --git a/src/libs/ReceiptUtils.js b/src/libs/ReceiptUtils.js index c9c6fcffa3f0..03781db0fa31 100644 --- a/src/libs/ReceiptUtils.js +++ b/src/libs/ReceiptUtils.js @@ -69,13 +69,4 @@ function isBeingScanned(receipt) { return receipt.state === CONST.IOU.RECEIPT_STATE.SCANREADY || receipt.state === CONST.IOU.RECEIPT_STATE.SCANNING; } -/** - * Returns the URL of a receipt given a filename - * @param {String} filename - * @returns {String} - */ -function getURL(filename) { - return `${CONFIG.EXPENSIFY.EXPENSIFY_URL}receipts/${filename}`; -} - -export {validateReceipt, getThumbnailAndImageURIs, getURL, isBeingScanned}; +export {validateReceipt, getThumbnailAndImageURIs, isBeingScanned}; diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index f7cdd3168f27..28f11d6ac261 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -151,7 +151,9 @@ function getCreated(transaction) { * @returns {Boolean} */ function isDistanceRequest(transaction) { - return transaction && transaction.type === CONST.TRANSACTION.TYPE.CUSTOM_UNIT && transaction.customUnit && transaction.customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE; + 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 {buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, getDescription, getAmount, getCurrency, getCreated, isDistanceRequest}; From 1817b399612755a03dca49190dca5eae2b578f6a Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 16 Aug 2023 11:45:52 -0600 Subject: [PATCH 10/17] Fix whitespace --- src/components/ReportActionItem/MoneyRequestView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index c65302483342..76f53965633b 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -92,7 +92,7 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic if (ReportActionsUtils.isDeletedAction(parentReportAction)) { return null; } - + const transaction = TransactionUtils.getTransaction(parentReportAction.originalMessage.IOUTransactionID); const hasReceipt = TransactionUtils.hasReceipt(transaction); let receiptURIs; From c40ebaeb83fddb9d2b6c644d7114cd061c86b0db Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 16 Aug 2023 11:59:41 -0600 Subject: [PATCH 11/17] Fix bad merge --- src/libs/TransactionUtils.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 694b0d2fc891..b00948040892 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -1,10 +1,24 @@ import {format} from 'date-fns'; import lodashGet from 'lodash/get'; +import Onyx from 'react-native-onyx'; import _ from 'underscore'; import CONST from '../CONST'; +import ONYXKEYS from '../ONYXKEYS'; import DateUtils from './DateUtils'; import * as NumberUtils from './NumberUtils'; +let allTransactions = {}; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (val) => { + if (!val) { + return; + } + allTransactions = val; + }, +}); + /** * Optimistically generate a transaction. * @@ -87,6 +101,16 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep return updatedTransaction; } +/** + * Retrieve the particular transaction object given its ID. + * + * @param {String} transactionID + * @returns {Object} + */ +function getTransaction(transactionID) { + return lodashGet(allTransactions, `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {}); +} + /** * Return the comment field (referred to as description in the App) from the transaction. * The comment does not have its modifiedComment counterpart. @@ -181,11 +205,11 @@ export { buildOptimisticTransaction, hasReceipt, getUpdatedTransaction, - getTransaction, getDescription, getAmount, getCurrency, getCreated, getReportPreviewTransactionsWithReceipts, + getTransaction, isDistanceRequest, }; From 49d669c23129e67bb97b3b6fd6c6605217e5131c Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 16 Aug 2023 15:54:56 -0600 Subject: [PATCH 12/17] Remove duplicate receipt image --- src/components/ReportActionItem/MoneyRequestPreview.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index cb22f37c5d54..d103c5152a20 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -242,8 +242,6 @@ function MoneyRequestPreview(props) { hoverStyle={isScanning ? styles.moneyRequestPreviewBoxHover : undefined} /> )} - - {isDistanceRequest && } From e4428668c3a102557fb119536ad7570117d0ef89 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 18 Aug 2023 15:34:35 -0600 Subject: [PATCH 13/17] Remove unused import --- src/libs/ReceiptUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReceiptUtils.js b/src/libs/ReceiptUtils.js index fcf2b07cd010..c1c028073690 100644 --- a/src/libs/ReceiptUtils.js +++ b/src/libs/ReceiptUtils.js @@ -9,7 +9,6 @@ import ReceiptHTML from '../../assets/images/receipt-html.png'; import ReceiptDoc from '../../assets/images/receipt-doc.png'; import ReceiptGeneric from '../../assets/images/receipt-generic.png'; import ReceiptSVG from '../../assets/images/receipt-svg.png'; -import CONFIG from '../CONFIG'; function validateReceipt(file) { const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(file, 'name', '')); From 784dbf20e17af598f3e8927d5d629c8760ce3024 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 22 Aug 2023 14:49:13 -0600 Subject: [PATCH 14/17] DRY up the transaction proptypes --- src/components/DistanceRequest.js | 21 ++------------ .../ReportActionItem/MoneyRequestPreview.js | 20 ++----------- src/components/transactionPropTypes.js | 28 ++++++++++++++++++- src/pages/iou/WaypointEditor.js | 21 ++------------ 4 files changed, 33 insertions(+), 57 deletions(-) diff --git a/src/components/DistanceRequest.js b/src/components/DistanceRequest.js index 8f07c7c05ecf..52bd07a1b1a8 100644 --- a/src/components/DistanceRequest.js +++ b/src/components/DistanceRequest.js @@ -21,6 +21,7 @@ import useNetwork from '../hooks/useNetwork'; import useLocalize from '../hooks/useLocalize'; import Navigation from '../libs/Navigation/Navigation'; import ROUTES from '../ROUTES'; +import transactionPropTypes from './transactionPropTypes'; const MAX_WAYPOINTS = 25; const MAX_WAYPOINTS_TO_DISPLAY = 4; @@ -33,25 +34,7 @@ const propTypes = { transactionID: PropTypes.string, /** The optimistic transaction for this request */ - transaction: PropTypes.shape({ - /** The transactionID of this request */ - transactionID: PropTypes.string, - - /** The comment object on the transaction */ - comment: PropTypes.shape({ - /** The waypoints defining the distance request */ - waypoints: PropTypes.shape({ - /** The latitude of the waypoint */ - lat: PropTypes.number, - - /** The longitude of the waypoint */ - lng: PropTypes.number, - - /** The address of the waypoint */ - address: PropTypes.string, - }), - }), - }), + transaction: transactionPropTypes, /** Data about Mapbox token for calling Mapbox API */ mapboxAccessToken: PropTypes.shape({ diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index ff6f1ece361f..52241f615a60 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -31,6 +31,7 @@ import refPropTypes from '../refPropTypes'; import PressableWithFeedback from '../Pressable/PressableWithoutFeedback'; import * as ReceiptUtils from '../../libs/ReceiptUtils'; import ReportActionItemImages from './ReportActionItemImages'; +import transactionPropTypes from '../transactionPropTypes'; const propTypes = { /** The active IOUReport, used for Onyx subscription */ @@ -91,24 +92,7 @@ const propTypes = { ), /** The transaction attached to the action.message.iouTransactionID */ - transaction: PropTypes.shape({ - /** The name of the file for the receipt image. This is just the filename and doesn't come with any kind of a path */ - filename: PropTypes.string, - - /** The name of the transaction merchant */ - merchant: PropTypes.string, - - /** The type of transaction */ - type: PropTypes.string, - - /** Custom units attached to the transaction */ - customUnits: PropTypes.arrayOf( - PropTypes.shape({ - /** The name of the custom unit */ - name: PropTypes.string, - }), - ), - }), + transaction: transactionPropTypes, /** Session info for the currently logged in user. */ session: PropTypes.shape({ diff --git a/src/components/transactionPropTypes.js b/src/components/transactionPropTypes.js index 14bfc288f245..fa171c7d7c00 100644 --- a/src/components/transactionPropTypes.js +++ b/src/components/transactionPropTypes.js @@ -1,4 +1,6 @@ import PropTypes from 'prop-types'; +import _ from 'underscore'; +import CONST from '../CONST'; export default PropTypes.shape({ /** The transaction id */ @@ -28,11 +30,35 @@ export default PropTypes.shape({ /** The edited merchant name */ modifiedMerchant: PropTypes.string, - /** The comment added to the transaction */ + /** The comment object on the transaction */ comment: PropTypes.shape({ + /** The text of the comment */ comment: PropTypes.string, + + /** The waypoints defining the distance request */ + waypoints: PropTypes.shape({ + /** The latitude of the waypoint */ + lat: PropTypes.number, + + /** The longitude of the waypoint */ + lng: PropTypes.number, + + /** The address of the waypoint */ + address: PropTypes.string, + }), }), + /** The type of transaction */ + type: PropTypes.oneOf(_.values(CONST.TRANSACTION.TYPE)), + + /** Custom units attached to the transaction */ + customUnits: PropTypes.arrayOf( + PropTypes.shape({ + /** The name of the custom unit */ + name: PropTypes.string, + }), + ), + /** The original currency of the transaction */ currency: PropTypes.string, diff --git a/src/pages/iou/WaypointEditor.js b/src/pages/iou/WaypointEditor.js index d5c8009a25d3..a3f8f40f5372 100644 --- a/src/pages/iou/WaypointEditor.js +++ b/src/pages/iou/WaypointEditor.js @@ -18,6 +18,7 @@ import * as ValidationUtils from '../../libs/ValidationUtils'; import ROUTES from '../../ROUTES'; import {withNetwork} from '../../components/OnyxProvider'; import networkPropTypes from '../../components/networkPropTypes'; +import transactionPropTypes from '../../components/transactionPropTypes'; const propTypes = { /** The transactionID of the IOU */ @@ -35,25 +36,7 @@ const propTypes = { }), /** The optimistic transaction for this request */ - transaction: PropTypes.shape({ - /** The transactionID of this request */ - transactionID: PropTypes.string, - - /** The comment object on the transaction */ - comment: PropTypes.shape({ - /** The waypoints defining the distance request */ - waypoints: PropTypes.shape({ - /** The latitude of the waypoint */ - lat: PropTypes.number, - - /** The longitude of the waypoint */ - lng: PropTypes.number, - - /** The address of the waypoint */ - address: PropTypes.string, - }), - }), - }), + transaction: transactionPropTypes, /** Information about the network */ network: networkPropTypes.isRequired, From e5633493d0723529a43f69332eb575a4dc12766f Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 22 Aug 2023 14:55:34 -0600 Subject: [PATCH 15/17] Cleanup distance request check --- .../ReportActionItem/MoneyRequestPreview.js | 4 ++-- src/components/transactionPropTypes.js | 2 +- src/libs/TransactionUtils.js | 21 ++++--------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 52241f615a60..0112b2cca7f3 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -150,9 +150,9 @@ function MoneyRequestPreview(props) { let description = requestComment; const hasReceipt = TransactionUtils.hasReceipt(props.transaction); const isScanning = hasReceipt && TransactionUtils.isReceiptBeingScanned(props.transaction); - const isDistanceRequest = props.transaction && TransactionUtils.isDistanceRequest(props.transaction); + const isDistanceRequest = TransactionUtils.isDistanceRequest(props.transaction); - // On a distance request the merchange of the transaction will be used for the description since that's where it's stored in the database + // On a distance request the merchant of the transaction will be used for the description since that's where it's stored in the database if (isDistanceRequest) { description = props.transaction.merchant; } diff --git a/src/components/transactionPropTypes.js b/src/components/transactionPropTypes.js index fa171c7d7c00..f9bad284cf68 100644 --- a/src/components/transactionPropTypes.js +++ b/src/components/transactionPropTypes.js @@ -67,7 +67,7 @@ export default PropTypes.shape({ /** The receipt object associated with the transaction */ receipt: PropTypes.shape({ - receiptID: PropTypes.string, + receiptID: PropTypes.number, source: PropTypes.string, state: PropTypes.string, }), diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 437f056ea6b7..e73c2de2261d 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -224,19 +224,6 @@ function getCreated(transaction) { return ''; } -/** - * @param {Object} transaction - * @param {String} transaction.type - * @param {Object} [transaction.customUnit] - * @param {String} [transaction.customUnit.name] - * @returns {Boolean} - */ -function isDistanceRequest(transaction) { - 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; -} - /** * Get the transactions related to a report preview with receipts * Get the details linked to the IOU reportAction @@ -259,9 +246,10 @@ function isReceiptBeingScanned(transaction) { /** * @param {Object} transaction - * @param {String} transaction.type - * @param {Object} [transaction.customUnit] - * @param {String} [transaction.customUnit.name] + * @param {Object} transaction.comment + * @param {String} transaction.comment.type + * @param {Object} [transaction.comment.customUnit] + * @param {String} [transaction.comment.customUnit.name] * @returns {Boolean} */ function isDistanceRequest(transaction) { @@ -284,5 +272,4 @@ export { hasReceipt, isDistanceRequest, isReceiptBeingScanned, - isDistanceRequest, }; From 9fb9a1aed369077a3cdb50a11fde0d61828c49cf Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 23 Aug 2023 09:25:28 -0600 Subject: [PATCH 16/17] Add error fields to proptypes --- src/components/transactionPropTypes.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/transactionPropTypes.js b/src/components/transactionPropTypes.js index f9bad284cf68..66ed18a1f0b7 100644 --- a/src/components/transactionPropTypes.js +++ b/src/components/transactionPropTypes.js @@ -71,4 +71,7 @@ export default PropTypes.shape({ source: PropTypes.string, state: PropTypes.string, }), + + /** Server side errors keyed by microtime */ + errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)), }); From 50599fe4fc9b81718afa889ef2848ac1475cd9ec Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 23 Aug 2023 09:35:10 -0600 Subject: [PATCH 17/17] Remove extra export --- src/libs/TransactionUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index abc6d21f91ef..5e133d3a383b 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -304,5 +304,4 @@ export { isReceiptBeingScanned, validateWaypoints, isDistanceRequest, - isReceiptBeingScanned, };