Skip to content

Commit

Permalink
Merge pull request #18328 from Expensify/yuwen-optimisticIOU2
Browse files Browse the repository at this point in the history
Simplify failure data for request/send money and make it more consistent with SplitBill
  • Loading branch information
luacmartins authored May 9, 2023
2 parents eb8c608 + 1a7f2e3 commit a0c9c24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ function requestMoney(report, amount, currency, recipientEmail, participant, com
errorFields: null,
},
};
chatReportFailureData.value.pendingFields = {createChat: null};
delete chatReportFailureData.value.hasOutstandingIOU;
chatReportFailureData.value.errorFields = {
createChat: {
[DateUtils.getMicroseconds()]: Localize.translateLocal('report.genericCreateReportFailureMessage'),
Expand All @@ -198,6 +200,10 @@ function requestMoney(report, amount, currency, recipientEmail, participant, com
// Then add an optimistic created action
optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;
reportActionsSuccessData.value[optimisticCreatedAction.reportActionID] = {pendingAction: null};

// Failure data should feature red brick road
reportActionsFailureData.value[optimisticCreatedAction.reportActionID] = {pendingAction: null};
reportActionsFailureData.value[optimisticReportAction.reportActionID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD};
}

const optimisticData = [
Expand Down Expand Up @@ -927,6 +933,9 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType

// Add an optimistic created action to the optimistic reportActions data
optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;

// If we're going to fail to create the report itself, let's not have redundant error messages for the IOU
failureData[0].value[optimisticIOUReportAction.reportActionID] = {pendingAction: null};
}

const optimisticData = [
Expand Down
2 changes: 0 additions & 2 deletions tests/actions/IOUTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,6 @@ describe('actions/IOU', () => {
expect(_.size(reportActionsForChatReport)).toBe(2);
iouAction = _.find(reportActionsForChatReport, reportAction => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU);
expect(iouAction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
const errorMessage = _.values(iouAction.errors)[0];
expect(errorMessage).toBe(Localize.translateLocal('iou.error.genericCreateFailureMessage'));
resolve();
},
});
Expand Down

0 comments on commit a0c9c24

Please sign in to comment.