Skip to content

Commit 5c8eeea

Browse files
committed
Expense with violation shows View instead of Review when report is not submitted by member
1 parent 99e31a5 commit 5c8eeea

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/libs/SearchUIUtils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,15 @@ function getAction(data: OnyxTypes.SearchResults['data'], allViolations: OnyxCol
711711
const policy = getPolicyFromKey(data, report) as OnyxTypes.Policy;
712712
const {isSubmitter, isAdmin, isApprover} = getReviewerPermissionFlags(report, policy);
713713

714+
const reportNVP = getReportNameValuePairsFromKey(data, report);
715+
const isIOUReportArchived = isArchivedReport(reportNVP);
716+
717+
const chatReportRNVP = data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`] ?? undefined;
718+
const isChatReportArchived = isArchivedReport(chatReportRNVP);
719+
714720
// Only check for violations if we need to (when user has permission to review)
715721
if ((isSubmitter || isApprover || isAdmin) && hasViolations(report.reportID, allViolations, undefined, allReportTransactions)) {
716-
if (isSubmitter && !isApprover && !isAdmin && !canReview(report, allViolations, policy, allReportTransactions)) {
722+
if (isSubmitter && !isApprover && !isAdmin && !canReview(report, allViolations, policy, allReportTransactions, isIOUReportArchived || isChatReportArchived)) {
717723
return CONST.SEARCH.ACTION_TYPES.VIEW;
718724
}
719725
return CONST.SEARCH.ACTION_TYPES.REVIEW;
@@ -730,7 +736,6 @@ function getAction(data: OnyxTypes.SearchResults['data'], allViolations: OnyxCol
730736
: undefined;
731737

732738
const chatReport = getChatReport(data, report);
733-
const chatReportRNVP = data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`] ?? undefined;
734739
const canBePaid = canIOUBePaid(report, chatReport, policy, allReportTransactions, false, chatReportRNVP, invoiceReceiverPolicy);
735740

736741
if (canBePaid && !hasOnlyHeldExpenses(report.reportID, allReportTransactions)) {
@@ -753,11 +758,8 @@ function getAction(data: OnyxTypes.SearchResults['data'], allViolations: OnyxCol
753758
return CONST.SEARCH.ACTION_TYPES.APPROVE;
754759
}
755760

756-
const reportNVP = getReportNameValuePairsFromKey(data, report);
757-
const isArchived = isArchivedReport(reportNVP);
758-
759761
// We check for isAllowedToApproveExpenseReport because if the policy has preventSelfApprovals enabled, we disable the Submit action and in that case we want to show the View action instead
760-
if (canSubmitReport(report, policy, allReportTransactions, allViolations, isArchived) && isAllowedToApproveExpenseReport) {
762+
if (canSubmitReport(report, policy, allReportTransactions, allViolations, isIOUReportArchived) && isAllowedToApproveExpenseReport) {
761763
return CONST.SEARCH.ACTION_TYPES.SUBMIT;
762764
}
763765

0 commit comments

Comments
 (0)