Skip to content

Commit ef00f0c

Browse files
authored
Merge pull request Expensify#60878 from bernhardoj/fix/59225-gbr-doesnt-show-when-pay-is-needed
2 parents 4b7a0a5 + c14d177 commit ef00f0c

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3605,7 +3605,7 @@ function getReasonAndReportActionThatRequiresAttention(
36053605
};
36063606
}
36073607

3608-
const iouReportActionToApproveOrPay = getIOUReportActionToApproveOrPay(optionOrReport, optionOrReport.reportID);
3608+
const iouReportActionToApproveOrPay = getIOUReportActionToApproveOrPay(optionOrReport, undefined);
36093609
const iouReportID = getIOUReportIDFromReportActionPreview(iouReportActionToApproveOrPay);
36103610
const transactions = getReportTransactions(iouReportID);
36113611
const hasOnlyPendingTransactions = transactions.length > 0 && transactions.every((t) => isExpensifyCardTransaction(t) && isPending(t));

src/libs/actions/IOU.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9248,29 +9248,24 @@ function canSubmitReport(
92489248
);
92499249
}
92509250

9251-
function getIOUReportActionToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report>, excludedIOUReportID: string | undefined): OnyxEntry<ReportAction> {
9251+
function getIOUReportActionToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report>, updatedIouReport: OnyxEntry<OnyxTypes.Report>): OnyxEntry<ReportAction> {
92529252
const chatReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`] ?? {};
92539253

92549254
return Object.values(chatReportActions).find((action) => {
92559255
if (!action) {
92569256
return false;
92579257
}
9258-
const iouReport = getReportOrDraftReport(action.childReportID);
9258+
const iouReport = updatedIouReport?.reportID === action.childReportID ? updatedIouReport : getReportOrDraftReport(action.childReportID);
92599259
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
92609260
// eslint-disable-next-line deprecation/deprecation
92619261
const policy = getPolicy(iouReport?.policyID);
92629262
const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy) || canApproveIOU(iouReport, policy);
9263-
return (
9264-
action.childReportID?.toString() !== excludedIOUReportID &&
9265-
action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW &&
9266-
shouldShowSettlementButton &&
9267-
!isDeletedAction(action)
9268-
);
9263+
return action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && shouldShowSettlementButton && !isDeletedAction(action);
92699264
});
92709265
}
92719266

9272-
function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report>, excludedIOUReportID: string | undefined): boolean {
9273-
return !!getIOUReportActionToApproveOrPay(chatReport, excludedIOUReportID);
9267+
function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report>, updatedIouReport: OnyxEntry<OnyxTypes.Report>): boolean {
9268+
return !!getIOUReportActionToApproveOrPay(chatReport, updatedIouReport);
92749269
}
92759270

92769271
function isLastApprover(approvalChain: string[]): boolean {
@@ -9320,27 +9315,28 @@ function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?:
93209315
},
93219316
},
93229317
};
9318+
const updatedExpenseReport = {
9319+
...expenseReport,
9320+
lastMessageText: getReportActionText(optimisticApprovedReportAction),
9321+
lastMessageHtml: getReportActionHtml(optimisticApprovedReportAction),
9322+
stateNum: predictedNextState,
9323+
statusNum: predictedNextStatus,
9324+
managerID,
9325+
pendingFields: {
9326+
partial: full ? null : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
9327+
},
9328+
};
93239329
const optimisticIOUReportData: OnyxUpdate = {
93249330
onyxMethod: Onyx.METHOD.MERGE,
93259331
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`,
9326-
value: {
9327-
...expenseReport,
9328-
lastMessageText: getReportActionText(optimisticApprovedReportAction),
9329-
lastMessageHtml: getReportActionHtml(optimisticApprovedReportAction),
9330-
stateNum: predictedNextState,
9331-
statusNum: predictedNextStatus,
9332-
managerID,
9333-
pendingFields: {
9334-
partial: full ? null : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
9335-
},
9336-
},
9332+
value: updatedExpenseReport,
93379333
};
93389334

93399335
const optimisticChatReportData: OnyxUpdate = {
93409336
onyxMethod: Onyx.METHOD.MERGE,
93419337
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.chatReportID}`,
93429338
value: {
9343-
hasOutstandingChildRequest: hasIOUToApproveOrPay(chatReport, expenseReport.reportID),
9339+
hasOutstandingChildRequest: hasIOUToApproveOrPay(chatReport, updatedExpenseReport),
93449340
},
93459341
};
93469342

0 commit comments

Comments
 (0)