From 8a8ce84ced23836c4507962141152476ac73d36e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 29 Nov 2023 23:51:54 +0700 Subject: [PATCH 01/11] fix optimistic merchant --- src/libs/actions/IOU.js | 30 ++++++++++++------- .../iou/steps/MoneyRequestConfirmPage.js | 3 ++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 939a11dad511..914b0df82a2d 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -908,12 +908,13 @@ 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} existingSplitChatReportID - the report ID where the split bill happens, could be a group chat or a workspace chat * * @return {Object} */ -function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '') { +function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, existingSplitChatReportID = '') { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = _.map(participants, (participant) => Number(participant.accountID)); const existingSplitChatReport = @@ -923,11 +924,6 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco const splitChatReport = existingSplitChatReport || ReportUtils.buildOptimisticChatReport(participantAccountIDs); const isOwnPolicyExpenseChat = splitChatReport.isOwnPolicyExpenseChat; - // ReportID is -2 (aka "deleted") on the group transaction: https://github.com/Expensify/Auth/blob/3fa2698654cd4fbc30f9de38acfca3fbeb7842e4/auth/command/SplitTransaction.cpp#L24-L27 - const formattedParticipants = isOwnPolicyExpenseChat - ? [currentUserLogin, ReportUtils.getReportName(splitChatReport)] - : Localize.arrayToString([currentUserLogin, ..._.map(participants, (participant) => participant.login || '')]); - const splitTransaction = TransactionUtils.buildOptimisticTransaction( amount, currency, @@ -936,7 +932,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco '', '', '', - `${Localize.translateLocal('iou.splitBill')} ${Localize.translateLocal('common.with')} ${formattedParticipants} [${DateUtils.getDBTime().slice(0, 10)}]`, + merchant, undefined, undefined, undefined, @@ -1244,11 +1240,22 @@ 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} existingSplitChatReportID - Either a group DM or a workspace chat */ -function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '') { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID); +function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, existingSplitChatReportID = '') { + const {splitData, splits, onyxData} = createSplitsAndOnyxData( + participants, + currentUserLogin, + currentUserAccountID, + amount, + comment, + currency, + merchant, + category, + existingSplitChatReportID, + ); API.write( 'SplitBill', { @@ -1278,10 +1285,11 @@ 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 */ -function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category) { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category); +function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category) { + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category); API.write( 'SplitBillAndOpenReport', diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index a69abeb94089..d63429425456 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -238,6 +238,7 @@ function MoneyRequestConfirmPage(props) { props.iou.amount, trimmedComment, props.iou.currency, + props.iou.merchant, props.iou.category, reportID, ); @@ -253,6 +254,7 @@ function MoneyRequestConfirmPage(props) { props.iou.amount, trimmedComment, props.iou.currency, + props.iou.merchant, props.iou.category, ); return; @@ -276,6 +278,7 @@ function MoneyRequestConfirmPage(props) { props.currentUserPersonalDetails.login, props.currentUserPersonalDetails.accountID, props.iou.currency, + props.iou.merchant, props.iou.category, props.iou.receiptPath, props.iou.receiptFilename, From 94f30d3f94ea82963992e83914f55848170860e4 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 30 Nov 2023 00:59:31 +0700 Subject: [PATCH 02/11] fix jest test --- src/libs/actions/IOU.js | 12 ++++++------ src/pages/iou/steps/MoneyRequestConfirmPage.js | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 914b0df82a2d..369f651f3b1b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1240,11 +1240,11 @@ 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} existingSplitChatReportID - Either a group DM or a workspace chat + * @param {String} merchant */ -function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, existingSplitChatReportID = '') { +function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant) { const {splitData, splits, onyxData} = createSplitsAndOnyxData( participants, currentUserLogin, @@ -1252,9 +1252,9 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, amount, comment, currency, - merchant, category, existingSplitChatReportID, + merchant, ); API.write( 'SplitBill', @@ -1285,11 +1285,11 @@ 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} merchant */ -function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category) { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category); +function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, merchant = '') { + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, '', merchant); API.write( 'SplitBillAndOpenReport', diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index d63429425456..3651f91a6ca4 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -238,9 +238,9 @@ function MoneyRequestConfirmPage(props) { props.iou.amount, trimmedComment, props.iou.currency, - props.iou.merchant, props.iou.category, reportID, + props.iou.merchant, ); return; } @@ -254,8 +254,8 @@ function MoneyRequestConfirmPage(props) { props.iou.amount, trimmedComment, props.iou.currency, - props.iou.merchant, props.iou.category, + props.iou.merchant, ); return; } @@ -278,7 +278,6 @@ function MoneyRequestConfirmPage(props) { props.currentUserPersonalDetails.login, props.currentUserPersonalDetails.accountID, props.iou.currency, - props.iou.merchant, props.iou.category, props.iou.receiptPath, props.iou.receiptFilename, @@ -288,6 +287,7 @@ function MoneyRequestConfirmPage(props) { receiptFile, iouType, reportID, + props.iou.merchant, ], ); From 55eb7f36a2146d02fe37beb0c539296286344008 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 30 Nov 2023 10:04:53 +0700 Subject: [PATCH 03/11] edit test --- tests/actions/IOUTest.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 944ec944648a..18793e88d624 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1115,9 +1115,7 @@ describe('actions/IOU', () => { 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( - `Split bill with ${RORY_EMAIL}, ${CARLOS_EMAIL}, ${JULES_EMAIL}, and ${VIT_EMAIL} [${DateUtils.getDBTime().slice(0, 10)}]`, - ); + expect(groupTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); expect(carlosTransaction.comment.source).toBe(CONST.IOU.TYPE.SPLIT); expect(julesTransaction.comment.source).toBe(CONST.IOU.TYPE.SPLIT); From d4baf3329bcc0550d7f73dc77e3462bb6eec6b55 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 30 Nov 2023 10:06:38 +0700 Subject: [PATCH 04/11] add change of previous pr --- src/components/ReportActionItem/MoneyRequestPreview.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 466a5a6eec51..652fb5a84e76 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -170,8 +170,7 @@ function MoneyRequestPreview(props) { const isDeleted = lodashGet(props.action, 'pendingAction', null) === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; // Show the merchant for IOUs and expenses only if they are custom or not related to scanning smartscan - const shouldShowMerchant = - !_.isEmpty(requestMerchant) && !props.isBillSplit && requestMerchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT && requestMerchant !== CONST.TRANSACTION.DEFAULT_MERCHANT; + const shouldShowMerchant = !_.isEmpty(requestMerchant) && requestMerchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT && requestMerchant !== CONST.TRANSACTION.DEFAULT_MERCHANT; const shouldShowDescription = !_.isEmpty(description) && !shouldShowMerchant && !isScanning; const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(props.transaction)] : []; @@ -322,7 +321,7 @@ function MoneyRequestPreview(props) { )} - {shouldShowMerchant && ( + {shouldShowMerchant && !props.isBillSplit && ( {hasPendingWaypoints ? requestMerchant.replace(CONST.REGEX.FIRST_SPACE, props.translate('common.tbd')) : requestMerchant} @@ -334,7 +333,9 @@ function MoneyRequestPreview(props) { {!isCurrentUserManager && props.shouldShowPendingConversionMessage && ( {props.translate('iou.pendingConversionMessage')} )} - {shouldShowDescription && {description}} + {(shouldShowDescription || (shouldShowMerchant && props.isBillSplit)) && ( + {shouldShowDescription ? description : requestMerchant} + )} {props.isBillSplit && !_.isEmpty(participantAccountIDs) && requestAmount > 0 && ( From eb126a1f5fd8933bb6fbeed3f541321956a6d59d Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:45:33 +0700 Subject: [PATCH 05/11] Update src/libs/actions/IOU.js Co-authored-by: Aimane Chnaif <96077027+aimane-chnaif@users.noreply.github.com> --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ddc8f44b907e..3769adafbcf4 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -925,7 +925,7 @@ function requestMoney( * * @return {Object} */ -function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, existingSplitChatReportID = '') { +function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant) { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = _.map(participants, (participant) => Number(participant.accountID)); const existingSplitChatReport = From a1d15a9824993f94883afcc4fbe57f67e2696c08 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 1 Dec 2023 22:49:21 +0700 Subject: [PATCH 06/11] re-order param --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3769adafbcf4..9a4c297567f5 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -919,9 +919,9 @@ 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} existingSplitChatReportID - the report ID where the split bill happens, could be a group chat or a workspace chat + * @param {String} merchant * * @return {Object} */ From 6642c603d98bed70694a4b524d469ffa3d835b96 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 1 Dec 2023 22:51:55 +0700 Subject: [PATCH 07/11] add default value for merchant param --- src/libs/actions/IOU.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 9a4c297567f5..678f0c7e6fbd 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -925,7 +925,7 @@ function requestMoney( * * @return {Object} */ -function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant) { +function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant = '') { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = _.map(participants, (participant) => Number(participant.accountID)); const existingSplitChatReport = @@ -1255,7 +1255,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco * @param {String} existingSplitChatReportID - Either a group DM or a workspace chat * @param {String} merchant */ -function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant) { +function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant = '') { const {splitData, splits, onyxData} = createSplitsAndOnyxData( participants, currentUserLogin, From 76569f5edb8e32348ebe75397ce6b3272b431672 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 1 Dec 2023 22:57:49 +0700 Subject: [PATCH 08/11] remove default value --- src/libs/actions/IOU.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 678f0c7e6fbd..f3cdd0a68b09 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -925,7 +925,7 @@ function requestMoney( * * @return {Object} */ -function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant = '') { +function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant) { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = _.map(participants, (participant) => Number(participant.accountID)); const existingSplitChatReport = @@ -1255,7 +1255,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco * @param {String} existingSplitChatReportID - Either a group DM or a workspace chat * @param {String} merchant */ -function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant = '') { +function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '', merchant) { const {splitData, splits, onyxData} = createSplitsAndOnyxData( participants, currentUserLogin, @@ -1299,7 +1299,7 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, * @param {String} category * @param {String} merchant */ -function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, merchant = '') { +function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, merchant) { const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, '', merchant); API.write( From 1083e35c42f568eb736799c9051e821f04da8536 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 2 Dec 2023 00:33:58 +0700 Subject: [PATCH 09/11] add merchant param in split bill API --- src/libs/actions/IOU.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index f3cdd0a68b09..bd8ddd62645a 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1276,6 +1276,7 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, currency, comment, category, + merchant, transactionID: splitData.transactionID, reportActionID: splitData.reportActionID, createdReportActionID: splitData.createdReportActionID, @@ -1311,6 +1312,7 @@ function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccou currency, comment, category, + merchant, transactionID: splitData.transactionID, reportActionID: splitData.reportActionID, createdReportActionID: splitData.createdReportActionID, From db14284cc599b678d6e1cc848ab0c837b41e4bbe Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 2 Dec 2023 00:38:25 +0700 Subject: [PATCH 10/11] add merchant in optimistic data of child transaction --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index bd8ddd62645a..38f8de861b06 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1133,7 +1133,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco '', CONST.IOU.TYPE.SPLIT, splitTransaction.transactionID, - undefined, + merchant, undefined, undefined, undefined, From 4708feda9f4b52eb3970889151a5423988d77695 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 2 Dec 2023 11:04:24 +0700 Subject: [PATCH 11/11] re-order tag param --- src/libs/actions/IOU.js | 4 ++-- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 33fec9c452f7..1d66ee0c96c8 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1264,10 +1264,10 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, * @param {String} comment * @param {String} currency * @param {String} category - * @param {String} merchant * @param {String} tag + * @param {String} merchant */ -function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, merchant, tag) { +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); API.write( 'SplitBillAndOpenReport', diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 05587c500ad5..50efdd511481 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -251,8 +251,8 @@ function MoneyRequestConfirmPage(props) { trimmedComment, props.iou.currency, props.iou.category, - props.iou.merchant, props.iou.tag, + props.iou.merchant, ); return; }