Skip to content

Commit

Permalink
Merge pull request #40096 from Expensify/alberto-fixSend
Browse files Browse the repository at this point in the history
Remove unneeded condition for Send Money/Request distance
  • Loading branch information
cristipaval authored Apr 11, 2024
2 parents 2c699e0 + 36c6c5b commit a7a6910
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnyxTypes.Report>,
participant: Participant,
comment: string,
created: string,
Expand All @@ -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 = {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<OnyxTypes.Report> | EmptyObject,
amount: number,
currency: string,
comment: string,
Expand All @@ -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;
Expand Down Expand Up @@ -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<OnyxTypes.Report>, 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});
Expand All @@ -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<OnyxTypes.Report>, 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});
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function IOURequestStepConfirmation({

const createDistanceRequest = useCallback(
(selectedParticipants: Participant[], trimmedComment: string) => {
if (!report || !transaction) {
if (!transaction) {
return;
}
IOU.createDistanceRequest(
Expand Down Expand Up @@ -433,7 +433,7 @@ function IOURequestStepConfirmation({

const participant = participants?.[0];

if (!participant || !report || !transaction?.amount || !currency) {
if (!participant || !transaction?.amount || !currency) {
return;
}

Expand Down

0 comments on commit a7a6910

Please sign in to comment.