diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 40a7d5a52f24..bcc0dac93066 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1491,7 +1491,7 @@ function getTrackExpenseInformation( /** Requests money based on a distance (e.g. mileage from a map) */ function createDistanceRequest( - report: OnyxTypes.Report, + report: OnyxEntry, participant: Participant, comment: string, created: string, @@ -1508,8 +1508,8 @@ function createDistanceRequest( ) { // 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 moneyRequestReportID = isMoneyRequestReport ? report.reportID : ''; + const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report?.chatReportID) : report; + const moneyRequestReportID = isMoneyRequestReport ? report?.reportID : ''; const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created); const optimisticReceipt: Receipt = { @@ -1569,7 +1569,7 @@ function createDistanceRequest( }; API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData); - Navigation.dismissModal(isMoneyRequestReport ? report.reportID : chatReport.reportID); + Navigation.dismissModal(isMoneyRequestReport ? report?.reportID : chatReport.reportID); Report.notifyNewAction(chatReport.reportID, userAccountID); } @@ -4313,7 +4313,7 @@ function deleteTrackExpense(chatReportID: string, transactionID: string, reportA * @param recipient - The user receiving the money */ function getSendMoneyParams( - report: OnyxTypes.Report, + report: OnyxEntry | EmptyObject, amount: number, currency: string, comment: string, @@ -4332,11 +4332,8 @@ function getSendMoneyParams( idempotencyKey: Str.guid(), }); - let chatReport = report.reportID ? report : null; + let chatReport = !isEmptyObject(report) && report?.reportID ? report : ReportUtils.getChatByParticipants([recipientAccountID]); let isNewChat = false; - if (!chatReport) { - chatReport = ReportUtils.getChatByParticipants([recipientAccountID]); - } if (!chatReport) { chatReport = ReportUtils.buildOptimisticChatReport([recipientAccountID]); isNewChat = true; @@ -4768,7 +4765,7 @@ function getPayMoneyRequestParams( * @param managerID - Account ID of the person sending the money * @param recipient - The user receiving the money */ -function sendMoneyElsewhere(report: OnyxTypes.Report, amount: number, currency: string, comment: string, managerID: number, recipient: Participant) { +function sendMoneyElsewhere(report: OnyxEntry, amount: number, currency: string, comment: string, managerID: number, recipient: Participant) { const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, managerID, recipient); API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData}); @@ -4782,7 +4779,7 @@ function sendMoneyElsewhere(report: OnyxTypes.Report, amount: number, currency: * @param managerID - Account ID of the person sending the money * @param recipient - The user receiving the money */ -function sendMoneyWithWallet(report: OnyxTypes.Report, amount: number, currency: string, comment: string, managerID: number, recipient: Participant | ReportUtils.OptionData) { +function sendMoneyWithWallet(report: OnyxEntry, amount: number, currency: string, comment: string, managerID: number, recipient: Participant | ReportUtils.OptionData) { const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.EXPENSIFY, managerID, recipient); API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData}); diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 897af48f0573..4273e7387457 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -236,7 +236,7 @@ function IOURequestStepConfirmation({ const createDistanceRequest = useCallback( (selectedParticipants: Participant[], trimmedComment: string) => { - if (!report || !transaction) { + if (!transaction) { return; } IOU.createDistanceRequest( @@ -433,7 +433,7 @@ function IOURequestStepConfirmation({ const participant = participants?.[0]; - if (!participant || !report || !transaction?.amount || !currency) { + if (!participant || !transaction?.amount || !currency) { return; }