Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Track when a split is created from global create to call proper API #32878

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 : '';
Copy link
Contributor Author

@tgolen tgolen Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an existing bug. reportID is a reference to the reportID coming from the URL route, and that will always be a number. This changes the code so that it's testing if the report.reportID belongs to an optimistic report or not, which I think is what is intended.

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