@@ -26,6 +26,7 @@ import {
2626 isInstantSubmitEnabled ,
2727 isMultiLevelTags as isMultiLevelTagsPolicyUtils ,
2828 isPolicyAdmin ,
29+ isPolicyMember as isPolicyMemberPolicyUtils ,
2930} from '@libs/PolicyUtils' ;
3031import { getOriginalMessage , getReportAction , isMoneyRequestAction } from '@libs/ReportActionsUtils' ;
3132import {
@@ -45,7 +46,19 @@ import CONST from '@src/CONST';
4546import type { IOUType } from '@src/CONST' ;
4647import IntlStore from '@src/languages/IntlStore' ;
4748import ONYXKEYS from '@src/ONYXKEYS' ;
48- import type { OnyxInputOrEntry , Policy , RecentWaypoint , Report , ReviewDuplicates , TaxRate , TaxRates , Transaction , TransactionViolation , TransactionViolations } from '@src/types/onyx' ;
49+ import type {
50+ OnyxInputOrEntry ,
51+ Policy ,
52+ RecentWaypoint ,
53+ Report ,
54+ ReviewDuplicates ,
55+ TaxRate ,
56+ TaxRates ,
57+ Transaction ,
58+ TransactionViolation ,
59+ TransactionViolations ,
60+ ViolationName ,
61+ } from '@src/types/onyx' ;
4962import type { Attendee , Participant , SplitExpense } from '@src/types/onyx/IOU' ;
5063import type { Errors , PendingAction } from '@src/types/onyx/OnyxCommon' ;
5164import type { SearchPolicy , SearchReport , SearchTransaction } from '@src/types/onyx/SearchResults' ;
@@ -984,6 +997,33 @@ function shouldShowBrokenConnectionViolationForMultipleTransactions(
984997 return shouldShowBrokenConnectionViolationInternal ( brokenConnectionViolations , report , policy ) ;
985998}
986999
1000+ /**
1001+ * Check if the user should see the violation
1002+ */
1003+ function shouldShowViolation ( iouReport : OnyxEntry < Report > , policy : OnyxEntry < Policy > , violationName : ViolationName ) : boolean {
1004+ const isSubmitter = isCurrentUserSubmitter ( iouReport ?. reportID ) ;
1005+ const isPolicyMember = isPolicyMemberPolicyUtils ( currentUserEmail , policy ?. id ) ;
1006+ const isReportOpen = isOpenExpenseReport ( iouReport ) ;
1007+
1008+ if ( violationName === CONST . VIOLATIONS . AUTO_REPORTED_REJECTED_EXPENSE ) {
1009+ return isSubmitter ;
1010+ }
1011+
1012+ if ( violationName === CONST . VIOLATIONS . OVER_AUTO_APPROVAL_LIMIT ) {
1013+ return isPolicyAdmin ( policy ) && ! isSubmitter ;
1014+ }
1015+
1016+ if ( violationName === CONST . VIOLATIONS . RTER ) {
1017+ return isSubmitter || isInstantSubmitEnabled ( policy ) ;
1018+ }
1019+
1020+ if ( violationName === CONST . VIOLATIONS . RECEIPT_NOT_SMART_SCANNED ) {
1021+ return isPolicyMember && ! isSubmitter && ! isReportOpen ;
1022+ }
1023+
1024+ return true ;
1025+ }
1026+
9871027/**
9881028 * Check if there is pending rter violation in all transactionViolations with given transactionIDs.
9891029 */
@@ -1774,6 +1814,7 @@ export {
17741814 getTransactionPendingAction ,
17751815 isTransactionPendingDelete ,
17761816 createUnreportedExpenseSections ,
1817+ shouldShowViolation ,
17771818 isUnreportedAndHasInvalidDistanceRateTransaction ,
17781819} ;
17791820
0 commit comments