Skip to content

Commit

Permalink
Merge pull request #30881 from paultsimura/fix/30407-distance-from-ex…
Browse files Browse the repository at this point in the history
…pense

fix: allow creating Distance request from expense reports
  • Loading branch information
neil-marcellini authored Nov 8, 2023
2 parents 24f306c + 98327c2 commit 49f730f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,16 @@ function getMoneyRequestInformation(
* @param {Boolean} [billable]
*/
function createDistanceRequest(report, participant, comment, created, transactionID, category, tag, amount, currency, merchant, billable) {
// If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report;

const optimisticReceipt = {
source: ReceiptGeneric,
state: CONST.IOU.RECEIPT_STATE.OPEN,
};
const {iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = getMoneyRequestInformation(
report,
currentChatReport,
participant,
comment,
amount,
Expand Down Expand Up @@ -660,7 +664,7 @@ function createDistanceRequest(report, participant, comment, created, transactio
},
onyxData,
);
Navigation.dismissModal(chatReport.reportID);
Navigation.dismissModal(isMoneyRequestReport ? report.reportID : chatReport.reportID);
Report.notifyNewAction(chatReport.reportID, userAccountID);
}

Expand Down
5 changes: 3 additions & 2 deletions src/pages/iou/MoneyRequestSelectorPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ function MoneyRequestSelectorPage(props) {
[CONST.IOU.TYPE.SPLIT]: translate('iou.splitBill'),
};
const isFromGlobalCreate = !reportID;
const isExpenseRequest = ReportUtils.isPolicyExpenseChat(props.report);
const shouldDisplayDistanceRequest = isExpenseRequest || isFromGlobalCreate;
const isExpenseChat = ReportUtils.isPolicyExpenseChat(props.report);
const isExpenseReport = ReportUtils.isExpenseReport(props.report);
const shouldDisplayDistanceRequest = isExpenseChat || isExpenseReport || isFromGlobalCreate;

const resetMoneyRequestInfo = () => {
const moneyRequestID = `${iouType}${reportID}`;
Expand Down

0 comments on commit 49f730f

Please sign in to comment.