Repository navigation
fix: Approving a report causes the workspace chat to “flash” in the LHN before disappearing #35928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0ddffd1
933cf9d
fda9b4e
11800a4
9d5d2c7
99e950b
293223f
4ecbd81
b6d451f
d5f7f3a
a54129e
d46b13a
c290a70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3677,10 +3677,73 @@ function sendMoneyWithWallet(report: OnyxTypes.Report, amount: number, currency: | |
| Report.notifyNewAction(params.chatReportID, managerID); | ||
| } | ||
|
|
||
| function canIOUBePaid(iouReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, policy: OnyxEntry<OnyxTypes.Policy> | EmptyObject) { | ||
| const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); | ||
| const iouCanceled = ReportUtils.isArchivedRoom(chatReport); | ||
|
|
||
| if (isEmptyObject(iouReport)) { | ||
| return false; | ||
| } | ||
|
|
||
| const isPayer = ReportUtils.isPayer( | ||
| { | ||
| email: currentUserEmail, | ||
| accountID: userAccountID, | ||
| }, | ||
| iouReport, | ||
| ); | ||
|
|
||
| const isDraftExpenseReport = isPolicyExpenseChat && ReportUtils.isDraftExpenseReport(iouReport); | ||
| const iouSettled = ReportUtils.isSettled(iouReport?.reportID); | ||
|
|
||
| const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); | ||
| const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(iouReport, policy); | ||
| return isPayer && !isDraftExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && reimbursableSpend !== 0 && !iouCanceled && !isAutoReimbursable; | ||
| } | ||
|
|
||
| function canApproveIOU(iouReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, policy: OnyxEntry<OnyxTypes.Policy> | EmptyObject) { | ||
| if (isEmptyObject(chatReport)) { | ||
| return false; | ||
| } | ||
| const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport); | ||
| if (!isPaidGroupPolicy) { | ||
| return false; | ||
| } | ||
|
|
||
| const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy); | ||
| const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); | ||
| if (isOnInstantSubmitPolicy && isOnSubmitAndClosePolicy) { | ||
| return false; | ||
| } | ||
|
|
||
| const managerID = iouReport?.managerID ?? 0; | ||
| const isCurrentUserManager = managerID === userAccountID; | ||
| const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); | ||
|
|
||
| const isDraftExpenseReport = isPolicyExpenseChat && ReportUtils.isDraftExpenseReport(iouReport); | ||
| const isApproved = ReportUtils.isReportApproved(iouReport); | ||
| const iouSettled = ReportUtils.isSettled(iouReport?.reportID); | ||
|
|
||
| return isCurrentUserManager && !isDraftExpenseReport && !isApproved && !iouSettled; | ||
| } | ||
|
|
||
| function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObject, excludedIOUReportID: string): boolean { | ||
| const chatReportActions = ReportActionsUtils.getAllReportActions(chatReport?.reportID ?? ''); | ||
|
|
||
| return Object.values(chatReportActions).some((action) => { | ||
| const iouReport = ReportUtils.getReport(action.childReportID ?? ''); | ||
| const policy = ReportUtils.getPolicy(iouReport?.policyID); | ||
|
|
||
| const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy) || canApproveIOU(iouReport, chatReport, policy); | ||
| return action.childReportID?.toString() !== excludedIOUReportID && action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && shouldShowSettlementButton; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should exclude deleted action here. Or it would cause #63875. |
||
| }); | ||
| } | ||
|
|
||
| function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject) { | ||
| const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; | ||
| const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID); | ||
| const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.APPROVED); | ||
| const chatReport = ReportUtils.getReport(expenseReport.chatReportID); | ||
|
|
||
| const optimisticReportActionsData: OnyxUpdate = { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
|
|
@@ -3703,12 +3766,21 @@ function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject) { | |
| statusNum: CONST.REPORT.STATUS_NUM.APPROVED, | ||
| }, | ||
| }; | ||
|
|
||
| const optimisticChatReportData: OnyxUpdate = { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`, | ||
| value: { | ||
| hasOutstandingChildRequest: hasIOUToApproveOrPay(chatReport, expenseReport?.reportID ?? ''), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We missed to check if the report was fully approved before passing |
||
| }, | ||
| }; | ||
|
|
||
| const optimisticNextStepData: OnyxUpdate = { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, | ||
| value: optimisticNextStep, | ||
| }; | ||
| const optimisticData: OnyxUpdate[] = [optimisticIOUReportData, optimisticReportActionsData, optimisticNextStepData]; | ||
| const optimisticData: OnyxUpdate[] = [optimisticIOUReportData, optimisticReportActionsData, optimisticNextStepData, optimisticChatReportData]; | ||
|
|
||
| const successData: OnyxUpdate[] = [ | ||
| { | ||
|
|
@@ -3732,6 +3804,13 @@ function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject) { | |
| }, | ||
| }, | ||
| }, | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.chatReportID}`, | ||
| value: { | ||
| hasOutstandingChildRequest: chatReport?.hasOutstandingChildRequest, | ||
| }, | ||
| }, | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, | ||
|
|
@@ -4331,4 +4410,6 @@ export { | |
| cancelPayment, | ||
| navigateToStartStepIfScanFileCannotBeRead, | ||
| savePreferredPaymentMethod, | ||
| canIOUBePaid, | ||
| canApproveIOU, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how costly the methods above are, but maybe consider moving this if to be right at the top?