From 18faa7f49ec84b52c6f1c7ba1c24987e37e162ce Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 12 Dec 2023 11:33:22 +0000 Subject: [PATCH] Merge pull request #32878 from Expensify/tgolen-fix-split-participants Track when a split is created from global create to call proper API (cherry picked from commit 4bcdcf505fc2652bdc9dc236aaa069a44cd89144) --- src/libs/actions/IOU.js | 4 +++- src/pages/iou/request/IOURequestStartPage.js | 10 +++++----- .../iou/request/step/IOURequestStepConfirmation.js | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 321e3fd6bb25..de5a4da5c5f6 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -92,9 +92,10 @@ Onyx.connect({ /** * Initialize money request info * @param {String} reportID to attach the transaction to + * @param {Boolean} isFromGlobalCreate * @param {String} [iouRequestType] one of manual/scan/distance */ -function startMoneyRequest_temporaryForRefactor(reportID, iouRequestType = CONST.IOU.REQUEST_TYPE.MANUAL) { +function startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, iouRequestType = CONST.IOU.REQUEST_TYPE.MANUAL) { // Generate a brand new transactionID const newTransactionID = CONST.IOU.OPTIMISTIC_TRANSACTION_ID; const created = currentDate || format(new Date(), 'yyyy-MM-dd'); @@ -118,6 +119,7 @@ function startMoneyRequest_temporaryForRefactor(reportID, iouRequestType = CONST iouRequestType, reportID, transactionID: newTransactionID, + isFromGlobalCreate, }); } diff --git a/src/pages/iou/request/IOURequestStartPage.js b/src/pages/iou/request/IOURequestStartPage.js index 8c0f00af95e0..48efc0bdd17c 100644 --- a/src/pages/iou/request/IOURequestStartPage.js +++ b/src/pages/iou/request/IOURequestStartPage.js @@ -68,6 +68,7 @@ function IOURequestStartPage({ }; const transactionRequestType = useRef(TransactionUtils.getRequestType(transaction)); const previousIOURequestType = usePrevious(transactionRequestType.current); + const isFromGlobalCreate = _.isEmpty(report.reportID); // Clear out the temporary money request when this component is unmounted useEffect( @@ -82,10 +83,9 @@ function IOURequestStartPage({ if (transaction.reportID === reportID) { return; } - IOU.startMoneyRequest_temporaryForRefactor(reportID, transactionRequestType.current); - }, [transaction, reportID, iouType]); + IOU.startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, transactionRequestType.current); + }, [transaction, reportID, iouType, isFromGlobalCreate]); - const isFromGlobalCreate = _.isEmpty(report.reportID); const isExpenseChat = ReportUtils.isPolicyExpenseChat(report); const isExpenseReport = ReportUtils.isExpenseReport(report); const shouldDisplayDistanceRequest = isExpenseChat || isExpenseReport || isFromGlobalCreate; @@ -102,10 +102,10 @@ function IOURequestStartPage({ if (newIouType === previousIOURequestType) { return; } - IOU.startMoneyRequest_temporaryForRefactor(reportID, newIouType); + IOU.startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, newIouType); transactionRequestType.current = newIouType; }, - [previousIOURequestType, reportID], + [previousIOURequestType, reportID, isFromGlobalCreate], ); return ( diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 2216d4c30bdf..859035606a31 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -192,14 +192,14 @@ 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(reportID) ? reportID : ''; + const existingSplitChatReportID = CONST.REGEX.NUMBER.test(report.reportID) ? reportID : ''; IOU.startSplitBill(selectedParticipants, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, trimmedComment, receiptFile, existingSplitChatReportID); return; } // IOUs created from a group report will have a reportID param in the route. // Since the user is already viewing the report, we don't need to navigate them to the report - if (iouType === CONST.IOU.TYPE.SPLIT && CONST.REGEX.NUMBER.test(reportID)) { + if (iouType === CONST.IOU.TYPE.SPLIT && !transaction.isFromGlobalCreate) { IOU.splitBill( selectedParticipants, currentUserPersonalDetails.login,