Skip to content

Commit 3d818ef

Browse files
authored
Merge pull request Expensify#64209 from eh2077/63114
fix: submitted expense shows Review button in Reports
2 parents 76728bc + f9e7e73 commit 3d818ef

5 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportU
3535
import Navigation from '@libs/Navigation/Navigation';
3636
import Performance from '@libs/Performance';
3737
import {getConnectedIntegration} from '@libs/PolicyUtils';
38-
import getReportPreviewAction from '@libs/ReportPreviewActionUtils';
38+
import {getReportPreviewAction} from '@libs/ReportPreviewActionUtils';
3939
import {
4040
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
4141
getBankAccountRoute,

src/libs/ReportPreviewActionUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,4 @@ function getReportPreviewAction(
253253
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW;
254254
}
255255

256-
export default getReportPreviewAction;
256+
export {canReview, getReportPreviewAction};

src/libs/SearchUIUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import Parser from './Parser';
4545
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
4646
import {canSendInvoice, getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy} from './PolicyUtils';
4747
import {getOriginalMessage, isCreatedAction, isDeletedAction, isMoneyRequestAction, isResolvedActionableWhisper, isWhisperActionTargetedToOthers} from './ReportActionsUtils';
48+
import {canReview} from './ReportPreviewActionUtils';
4849
import {
4950
getIcons,
5051
getPersonalDetailsForAccountID,
@@ -680,6 +681,9 @@ function getAction(data: OnyxTypes.SearchResults['data'], allViolations: OnyxCol
680681

681682
// Only check for violations if we need to (when user has permission to review)
682683
if ((isSubmitter || isApprover || isAdmin) && hasViolations(report.reportID, allViolations, undefined, allReportTransactions)) {
684+
if (isSubmitter && !isApprover && !isAdmin && !canReview(report, allViolations, policy, allReportTransactions)) {
685+
return CONST.SEARCH.ACTION_TYPES.VIEW;
686+
}
683687
return CONST.SEARCH.ACTION_TYPES.REVIEW;
684688
}
685689
// Submit/Approve/Pay can only be taken on transactions if the transaction is the only one on the report, otherwise `View` is the only option.

tests/actions/ReportPreviewActionUtilsTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Onyx from 'react-native-onyx';
44
import useReportIsArchived from '@hooks/useReportIsArchived';
55
// eslint-disable-next-line no-restricted-syntax
66
import type * as PolicyUtils from '@libs/PolicyUtils';
7-
import getReportPreviewAction from '@libs/ReportPreviewActionUtils';
7+
import {getReportPreviewAction} from '@libs/ReportPreviewActionUtils';
88
// eslint-disable-next-line no-restricted-syntax
99
import * as ReportUtils from '@libs/ReportUtils';
1010
import CONST from '@src/CONST';

tests/unit/Search/SearchUIUtilsTest.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const approverAccountID = 1111111;
2020
const approverEmail = 'approver@policy.com';
2121
const overlimitApproverAccountID = 222222;
2222
const overlimitApproverEmail = 'overlimit@policy.com';
23+
const submitterAccountID = 333333;
24+
const submitterEmail = 'submitter@policy.com';
2325
const policyID = 'A1B2C3';
2426
const reportID = '123456789';
2527
const reportID2 = '11111';
@@ -61,6 +63,12 @@ const searchResults: OnyxTypes.SearchResults = {
6163
displayName: 'Overlimit Approver',
6264
login: overlimitApproverEmail,
6365
},
66+
[submitterAccountID]: {
67+
accountID: submitterAccountID,
68+
avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png',
69+
displayName: 'Submitter',
70+
login: submitterEmail,
71+
},
6472
},
6573
[`policy_${policyID}`]: {
6674
id: 'Admin',
@@ -98,6 +106,11 @@ const searchResults: OnyxTypes.SearchResults = {
98106
role: CONST.POLICY.ROLE.ADMIN,
99107
submitsTo: approverEmail,
100108
},
109+
[submitterEmail]: {
110+
email: submitterEmail,
111+
role: CONST.POLICY.ROLE.USER,
112+
submitsTo: adminEmail,
113+
},
101114
},
102115
},
103116
[`reportActions_${reportID}`]: {
@@ -957,6 +970,29 @@ describe('SearchUIUtils', () => {
957970
expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT);
958971
});
959972

973+
test('Should return `View` action for transaction on policy with delayed submission and with violations when current user is submitter and the expense was submitted', async () => {
974+
await Onyx.merge(ONYXKEYS.SESSION, {accountID: submitterAccountID});
975+
const localSearchResults = {
976+
...searchResults.data,
977+
[`policy_${policyID}`]: {
978+
...searchResults.data[`policy_${policyID}`],
979+
role: CONST.POLICY.ROLE.USER,
980+
},
981+
[`report_${reportID2}`]: {
982+
...searchResults.data[`report_${reportID2}`],
983+
accountID: submitterAccountID,
984+
ownerAccountID: submitterAccountID,
985+
},
986+
[`transactions_${transactionID2}`]: {
987+
...searchResults.data[`transactions_${transactionID2}`],
988+
accountID: submitterAccountID,
989+
managerID: adminAccountID,
990+
},
991+
};
992+
expect(SearchUIUtils.getAction(localSearchResults, allViolations, `report_${reportID2}`)).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW);
993+
expect(SearchUIUtils.getAction(localSearchResults, allViolations, `transactions_${transactionID2}`)).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW);
994+
});
995+
960996
test('Should return `Review` action for transaction on policy with delayed submission and with violations', () => {
961997
let action = SearchUIUtils.getAction(searchResults.data, allViolations, `report_${reportID2}`);
962998
expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW);

0 commit comments

Comments
 (0)