-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix: Approving a report causes the workspace chat to “flash” in the LHN before disappearing #35928
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ddffd1
fix: Approving a report causes the workspace chat to “flash” in the L…
tienifr 933cf9d
fix conflict
tienifr fda9b4e
Merge branch 'main' into fix/35309
tienifr 11800a4
lint fix
tienifr 9d5d2c7
Merge branch 'main' into fix/35309
tienifr 99e950b
Merge branch 'main' into fix/35309
tienifr 293223f
refactor
tienifr 4ecbd81
resolve conflicts
tienifr b6d451f
resolve conflicts
tienifr d5f7f3a
resolve conflicts
tienifr a54129e
merge main
tienifr d46b13a
refactor
tienifr c290a70
refactor
tienifr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3673,10 +3673,64 @@ function sendMoneyWithWallet(report: OnyxTypes.Report, amount: number, currency: | |
Report.notifyNewAction(params.chatReportID, managerID); | ||
} | ||
|
||
function shouldShowPayButton(iouReport: OnyxEntry<OnyxTypes.Report>, chatReport: OnyxEntry<OnyxTypes.Report>, policy: OnyxEntry<OnyxTypes.Policy>) { | ||
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); | ||
const iouCanceled = ReportUtils.isArchivedRoom(chatReport); | ||
|
||
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 shouldShowApproveButton(iouReport: OnyxEntry<OnyxTypes.Report>, chatReport: OnyxEntry<OnyxTypes.Report>, policy: OnyxEntry<OnyxTypes.Policy>) { | ||
const managerID = iouReport?.managerID ?? 0; | ||
const isCurrentUserManager = managerID === userAccountID; | ||
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport); | ||
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); | ||
|
||
const isDraftExpenseReport = isPolicyExpenseChat && ReportUtils.isDraftExpenseReport(iouReport); | ||
const isApproved = ReportUtils.isReportApproved(iouReport); | ||
const iouSettled = ReportUtils.isSettled(iouReport?.reportID); | ||
const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy); | ||
const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); | ||
if (!isPaidGroupPolicy) { | ||
return false; | ||
} | ||
if (isOnInstantSubmitPolicy && isOnSubmitAndClosePolicy) { | ||
return false; | ||
} | ||
|
||
return isCurrentUserManager && !isDraftExpenseReport && !isApproved && !iouSettled; | ||
} | ||
|
||
function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report>, excludedIOUReportID: string): boolean { | ||
const chatReportActions = ReportActionsUtils.getAllReportActions(chatReport?.reportID ?? ''); | ||
|
||
return !!Object.values(chatReportActions).find((action) => { | ||
tienifr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const iouReport = ReportUtils.getReport(action.childReportID ?? '') as OnyxEntry<OnyxTypes.Report>; | ||
const policy = ReportUtils.getPolicy(iouReport?.policyID) as OnyxEntry<OnyxTypes.Policy>; | ||
tienifr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const shouldShowSettlementButton = shouldShowPayButton(iouReport, chatReport, policy) || shouldShowApproveButton(iouReport, chatReport, policy); | ||
return action.childReportID?.toString() !== excludedIOUReportID && action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && shouldShowSettlementButton; | ||
}); | ||
} | ||
|
||
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) as OnyxEntry<OnyxTypes.Report>; | ||
tienifr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const optimisticReportActionsData: OnyxUpdate = { | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
|
@@ -3699,12 +3753,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 ?? ''), | ||
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[] = [ | ||
{ | ||
|
@@ -3728,13 +3791,33 @@ 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}`, | ||
value: currentNextStep, | ||
}, | ||
]; | ||
|
||
if (currentNextStep) { | ||
optimisticData.push({ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, | ||
value: null, | ||
tienifr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
failureData.push({ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, | ||
value: currentNextStep, | ||
}); | ||
} | ||
|
||
const parameters: ApproveMoneyRequestParams = { | ||
reportID: expenseReport.reportID, | ||
approvedReportActionID: optimisticApprovedReportAction.reportActionID, | ||
|
@@ -4327,4 +4410,6 @@ export { | |
cancelPayment, | ||
navigateToStartStepIfScanFileCannotBeRead, | ||
savePreferredPaymentMethod, | ||
shouldShowPayButton, | ||
shouldShowApproveButton, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?