diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index d5e9fc8d1e391..20012bc90ef06 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -140,9 +140,6 @@ const propTypes = { /** Whether the money request is a distance request */ isDistanceRequest: PropTypes.bool, - /** Whether the money request is a scan request */ - isScanRequest: PropTypes.bool, - /** Whether we're editing a split bill */ isEditingSplitBill: PropTypes.bool, @@ -191,7 +188,6 @@ const defaultProps = { transaction: {}, mileageRate: {unit: CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate: 0, currency: 'USD'}, isDistanceRequest: false, - isScanRequest: false, shouldShowSmartScanFields: true, isPolicyExpenseChat: false, }; @@ -215,7 +211,6 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ isEditingSplitBill, isPolicyExpenseChat, isReadOnly, - isScanRequest, listStyles, mileageRate, onConfirm, @@ -244,8 +239,6 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ const isTypeSplit = iouType === CONST.IOU.TYPE.SPLIT; const isTypeSend = iouType === CONST.IOU.TYPE.SEND; - const isSplitWithScan = isTypeSplit && isScanRequest; - const {unit, rate, currency} = mileageRate; const distance = lodashGet(transaction, 'routes.route0.distance', 0); const shouldCalculateDistanceAmount = isDistanceRequest && iouAmount === 0; @@ -259,9 +252,8 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ // Do not hide fields in case of send money request const shouldShowAllFields = isDistanceRequest || shouldExpandFields || !shouldShowSmartScanFields || isTypeSend || isEditingSplitBill; - // In Send Money flow, we don't allow the Merchant or Date to be edited. For distance requests, don't show the merchant as there's already another "Distance" menu item - const shouldShowDate = shouldShowAllFields && !isTypeSend && !isSplitWithScan; - const shouldShowMerchant = shouldShowAllFields && !isTypeSend && !isDistanceRequest && !isSplitWithScan; + const shouldShowDate = shouldShowSmartScanFields || isDistanceRequest; + const shouldShowMerchant = shouldShowSmartScanFields && !isDistanceRequest; // Fetches the first tag list of the policy const policyTag = PolicyUtils.getTag(policyTags); diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 12c6d0629370f..35859914016d0 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -164,10 +164,16 @@ function MoneyRequestPreview(props) { // Show the merchant for IOUs and expenses only if they are custom or not related to scanning smartscan const shouldShowMerchant = !_.isEmpty(requestMerchant) && requestMerchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT && requestMerchant !== CONST.TRANSACTION.DEFAULT_MERCHANT; const shouldShowDescription = !_.isEmpty(description) && !shouldShowMerchant && !isScanning; + const hasPendingWaypoints = lodashGet(props.transaction, 'pendingFields.waypoints', null); - const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(props.transaction)] : []; + let merchantOrDescription = requestMerchant; + if (!shouldShowMerchant) { + merchantOrDescription = description || ''; + } else if (hasPendingWaypoints) { + merchantOrDescription = requestMerchant.replace(CONST.REGEX.FIRST_SPACE, translate('common.tbd')); + } - const hasPendingWaypoints = lodashGet(props.transaction, 'pendingFields.waypoints', null); + const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(props.transaction)] : []; const getSettledMessage = () => { if (isExpensifyCardTransaction) { @@ -315,21 +321,12 @@ function MoneyRequestPreview(props) { )} - {shouldShowMerchant && !props.isBillSplit && ( - - - {hasPendingWaypoints ? requestMerchant.replace(CONST.REGEX.FIRST_SPACE, translate('common.tbd')) : requestMerchant} - - - )} {!isCurrentUserManager && props.shouldShowPendingConversionMessage && ( {translate('iou.pendingConversionMessage')} )} - {(shouldShowDescription || (shouldShowMerchant && props.isBillSplit)) && ( - {shouldShowDescription ? description : requestMerchant} - )} + {(shouldShowDescription || shouldShowMerchant) && {merchantOrDescription}} {props.isBillSplit && !_.isEmpty(participantAccountIDs) && requestAmount > 0 && ( diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index a9d04654f8bd8..e30843f7f912f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1131,14 +1131,14 @@ function requestMoney( * @param {Number} amount - always in the smallest unit of the currency * @param {String} comment * @param {String} currency + * @param {String} merchant * @param {String} category * @param {String} tag * @param {String} existingSplitChatReportID - the report ID where the split bill happens, could be a group chat or a workspace chat - * @param {String} merchant * * @return {Object} */ -function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, existingSplitChatReportID = '', merchant) { +function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, tag, existingSplitChatReportID = '') { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = _.map(participants, (participant) => Number(participant.accountID)); const existingSplitChatReport = @@ -1156,7 +1156,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco '', '', '', - merchant, + merchant || Localize.translateLocal('iou.request'), undefined, undefined, undefined, @@ -1357,7 +1357,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco '', CONST.IOU.TYPE.SPLIT, splitTransaction.transactionID, - merchant, + merchant || Localize.translateLocal('iou.request'), undefined, undefined, undefined, @@ -1476,12 +1476,12 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco * @param {Number} amount - always in smallest currency unit * @param {String} comment * @param {String} currency + * @param {String} merchant * @param {String} category * @param {String} tag * @param {String} existingSplitChatReportID - Either a group DM or a workspace chat - * @param {String} merchant */ -function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, existingSplitChatReportID = '', merchant) { +function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, tag, existingSplitChatReportID = '') { const {splitData, splits, onyxData} = createSplitsAndOnyxData( participants, currentUserLogin, @@ -1489,10 +1489,10 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, amount, comment, currency, + merchant, category, tag, existingSplitChatReportID, - merchant, ); API.write( 'SplitBill', @@ -1525,12 +1525,13 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, * @param {Number} amount - always in smallest currency unit * @param {String} comment * @param {String} currency + * @param {String} merchant * @param {String} category * @param {String} tag - * @param {String} merchant */ -function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, merchant) { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, '', merchant); +function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, tag) { + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, tag); + API.write( 'SplitBillAndOpenReport', { @@ -1538,9 +1539,9 @@ function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccou amount, splits: JSON.stringify(splits), currency, + merchant, comment, category, - merchant, tag, transactionID: splitData.transactionID, reportActionID: splitData.reportActionID, @@ -1562,10 +1563,12 @@ function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccou * @param {String} currentUserLogin * @param {Number} currentUserAccountID * @param {String} comment + * @param {String} category + * @param {String} tag * @param {Object} receipt * @param {String} existingSplitChatReportID - Either a group DM or a workspace chat */ -function startSplitBill(participants, currentUserLogin, currentUserAccountID, comment, receipt, existingSplitChatReportID = '') { +function startSplitBill(participants, currentUserLogin, currentUserAccountID, comment, category, tag, receipt, existingSplitChatReportID = '') { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = _.map(participants, (participant) => Number(participant.accountID)); const existingSplitChatReport = @@ -1774,6 +1777,8 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co splits: JSON.stringify(splits), receipt, comment, + category, + tag, isFromGroupDM: !existingSplitChatReport, ...(existingSplitChatReport ? {} : {createdReportActionID: splitChatCreatedReportAction.reportActionID}), }, @@ -1981,6 +1986,8 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi created: transactionCreated, merchant: transactionMerchant, comment: transactionComment, + category: transactionCategory, + tag: transactionTag, } = ReportUtils.getTransactionDetails(updatedTransaction); API.write( @@ -1992,6 +1999,8 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi created: transactionCreated, merchant: transactionMerchant, comment: transactionComment, + category: transactionCategory, + tag: transactionTag, splits: JSON.stringify(splits), }, {optimisticData, successData, failureData}, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 6d5375c7a1bb7..cb6225b641fc8 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -194,8 +194,17 @@ function IOURequestStepConfirmation({ // If we have a receipt let's start the split bill by creating only the action, the transaction, and the group DM if needed if (iouType === CONST.IOU.TYPE.SPLIT && receiptFile) { - const existingSplitChatReportID = CONST.REGEX.NUMBER.test(report.reportID) ? reportID : ''; - IOU.startSplitBill(selectedParticipants, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, trimmedComment, receiptFile, existingSplitChatReportID); + const existingSplitChatReportID = CONST.REGEX.NUMBER.test(reportID) ? reportID : ''; + IOU.startSplitBill( + selectedParticipants, + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + trimmedComment, + transaction.category, + transaction.tag, + receiptFile, + existingSplitChatReportID, + ); return; } @@ -209,10 +218,10 @@ function IOURequestStepConfirmation({ transaction.amount, trimmedComment, transaction.currency, + transaction.merchant, transaction.category, transaction.tag, report.reportID, - transaction.merchant, ); return; } @@ -226,9 +235,9 @@ function IOURequestStepConfirmation({ transaction.amount, trimmedComment, transaction.currency, + transaction.merchant, transaction.category, transaction.tag, - transaction.merchant, ); return; } @@ -337,7 +346,6 @@ function IOURequestStepConfirmation({ bankAccountRoute={ReportUtils.getBankAccountRoute(report)} iouMerchant={transaction.merchant} iouCreated={transaction.created} - isScanRequest={requestType === CONST.IOU.REQUEST_TYPE.SCAN} isDistanceRequest={requestType === CONST.IOU.REQUEST_TYPE.DISTANCE} shouldShowSmartScanFields={_.isEmpty(lodashGet(transaction, 'receipt.source', ''))} /> diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 97c1bf35732f9..bb7a7c3424d20 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -807,6 +807,7 @@ describe('actions/IOU', () => { */ const amount = 400; const comment = 'Yes, I am splitting a bill for $4 USD'; + const merchant = 'Yema Kitchen'; let carlosChatReport = { reportID: NumberUtils.rand64(), type: CONST.REPORT.TYPE.CHAT, @@ -923,6 +924,7 @@ describe('actions/IOU', () => { amount, comment, CONST.CURRENCY.USD, + merchant, ); return waitForBatchedUpdates(); }) @@ -1102,10 +1104,10 @@ describe('actions/IOU', () => { expect(vitTransaction.comment.comment).toBe(comment); expect(groupTransaction.comment.comment).toBe(comment); - expect(carlosTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); - expect(julesTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); - expect(vitTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); - expect(groupTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); + expect(carlosTransaction.merchant).toBe(merchant); + expect(julesTransaction.merchant).toBe(merchant); + expect(vitTransaction.merchant).toBe(merchant); + expect(groupTransaction.merchant).toBe(merchant); expect(carlosTransaction.comment.source).toBe(CONST.IOU.TYPE.SPLIT); expect(julesTransaction.comment.source).toBe(CONST.IOU.TYPE.SPLIT);