Skip to content

Commit

Permalink
Merge pull request #32878 from Expensify/tgolen-fix-split-participants
Browse files Browse the repository at this point in the history
Track when a split is created from global create to call proper API
  • Loading branch information
Julesssss authored Dec 12, 2023
2 parents 2d8523a + 16a4a13 commit 4bcdcf5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -118,6 +119,7 @@ function startMoneyRequest_temporaryForRefactor(reportID, iouRequestType = CONST
iouRequestType,
reportID,
transactionID: newTransactionID,
isFromGlobalCreate,
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/pages/iou/request/IOURequestStartPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4bcdcf5

Please sign in to comment.