Skip to content

Commit 2fc0566

Browse files
authored
Merge pull request #56553 from Expensify/puneet-customRules-violations
[No QA] Add violation for custom rules
2 parents 837edc9 + a5d3666 commit 2fc0566

File tree

9 files changed

+20
-1
lines changed

9 files changed

+20
-1
lines changed

src/CONST.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4998,6 +4998,7 @@ const CONST = {
49984998
PER_DAY_LIMIT: 'perDayLimit',
49994999
RECEIPT_NOT_SMART_SCANNED: 'receiptNotSmartScanned',
50005000
RECEIPT_REQUIRED: 'receiptRequired',
5001+
CUSTOM_RULES: 'customRules',
50015002
RTER: 'rter',
50025003
SMARTSCAN_FAILED: 'smartscanFailed',
50035004
SOME_TAG_LEVELS_REQUIRED: 'someTagLevelsRequired',

src/components/ReportActionItem/MoneyRequestView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type MoneyRequestViewProps = {
9393

9494
const receiptImageViolationNames: OnyxTypes.ViolationName[] = [
9595
CONST.VIOLATIONS.RECEIPT_REQUIRED,
96+
CONST.VIOLATIONS.CUSTOM_RULES,
9697
CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED,
9798
CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT,
9899
CONST.VIOLATIONS.SMARTSCAN_FAILED,
@@ -407,10 +408,12 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
407408
}, [transactionViolations, translate]);
408409

409410
const receiptRequiredViolation = transactionViolations?.some((violation) => violation.name === CONST.VIOLATIONS.RECEIPT_REQUIRED);
411+
const customRulesViolation = transactionViolations?.some((violation) => violation.name === CONST.VIOLATIONS.CUSTOM_RULES);
410412

411413
// Whether to show receipt audit result (e.g.`Verified`, `Issue Found`) and messages (e.g. `Receipt not verified. Please confirm accuracy.`)
412414
// `!!(receiptViolations.length || didReceiptScanSucceed)` is for not showing `Verified` when `receiptViolations` is empty and `didReceiptScanSucceed` is false.
413-
const shouldShowAuditMessage = !isReceiptBeingScanned && (hasReceipt || receiptRequiredViolation) && !!(receiptViolations.length || didReceiptScanSucceed) && isPaidGroupPolicy(report);
415+
const shouldShowAuditMessage =
416+
!isReceiptBeingScanned && (hasReceipt || !!receiptRequiredViolation || !!customRulesViolation) && !!(receiptViolations.length || didReceiptScanSucceed) && isPaidGroupPolicy(report);
414417
const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt);
415418

416419
const errors = {

src/hooks/useViolations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const violationFields: Record<ViolationName, ViolationField> = {
3636
perDayLimit: 'amount',
3737
receiptNotSmartScanned: 'receipt',
3838
receiptRequired: 'receipt',
39+
customRules: 'receipt',
3940
rter: 'merchant',
4041
smartscanFailed: 'receipt',
4142
someTagLevelsRequired: 'tag',

src/languages/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ import type {
184184
ViolationsAutoReportedRejectedExpenseParams,
185185
ViolationsCashExpenseWithNoReceiptParams,
186186
ViolationsConversionSurchargeParams,
187+
ViolationsCustomRulesParams,
187188
ViolationsInvoiceMarkupParams,
188189
ViolationsMaxAgeParams,
189190
ViolationsMissingTagParams,
@@ -5343,6 +5344,7 @@ const translations = {
53435344
}
53445345
return message;
53455346
},
5347+
customRules: ({message}: ViolationsCustomRulesParams) => message,
53465348
reviewRequired: 'Review required',
53475349
rter: ({brokenBankConnection, email, isAdmin, isTransactionOlderThan7Days, member, rterType}: ViolationsRterParams) => {
53485350
if (rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_530 || rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION) {

src/languages/es.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ import type {
183183
ViolationsAutoReportedRejectedExpenseParams,
184184
ViolationsCashExpenseWithNoReceiptParams,
185185
ViolationsConversionSurchargeParams,
186+
ViolationsCustomRulesParams,
186187
ViolationsInvoiceMarkupParams,
187188
ViolationsMaxAgeParams,
188189
ViolationsMissingTagParams,
@@ -5856,6 +5857,7 @@ const translations = {
58565857
}
58575858
return message;
58585859
},
5860+
customRules: ({message}: ViolationsCustomRulesParams) => message,
58595861
reviewRequired: 'Revisión requerida',
58605862
rter: ({brokenBankConnection, isAdmin, email, isTransactionOlderThan7Days, member, rterType}: ViolationsRterParams) => {
58615863
if (rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_530 || rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION) {

src/languages/params.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ type ViolationsPerDayLimitParams = {formattedLimit: string};
258258

259259
type ViolationsReceiptRequiredParams = {formattedLimit?: string; category?: string};
260260

261+
type ViolationsCustomRulesParams = {message: string};
262+
261263
type ViolationsRterParams = {
262264
brokenBankConnection: boolean;
263265
isAdmin: boolean;
@@ -774,6 +776,7 @@ export type {
774776
ViolationsOverLimitParams,
775777
ViolationsPerDayLimitParams,
776778
ViolationsReceiptRequiredParams,
779+
ViolationsCustomRulesParams,
777780
ViolationsRterParams,
778781
ViolationsTagOutOfPolicyParams,
779782
ViolationsTaxOutOfPolicyParams,

src/libs/DebugUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ function validateTransactionViolationDraftProperty(key: keyof TransactionViolati
12411241
duplicates: 'array',
12421242
rterType: CONST.RTER_VIOLATION_TYPES,
12431243
tooltip: 'string',
1244+
message: 'string',
12441245
});
12451246
case 'showInReview':
12461247
return validateBoolean(value);

src/libs/Violations/ViolationsUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ const ViolationsUtils = {
254254
taxName,
255255
type,
256256
rterType,
257+
message = '',
257258
} = violation.data ?? {};
258259

259260
switch (violation.name) {
@@ -310,6 +311,8 @@ const ViolationsUtils = {
310311
return translate('violations.receiptNotSmartScanned');
311312
case 'receiptRequired':
312313
return translate('violations.receiptRequired', {formattedLimit, category});
314+
case 'customRules':
315+
return translate('violations.customRules', {message});
313316
case 'rter':
314317
return translate('violations.rter', {
315318
brokenBankConnection,

src/types/onyx/TransactionViolation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ type TransactionViolationData = {
8989
/** Type of the RTER violation */
9090
rterType?: ValueOf<typeof CONST.RTER_VIOLATION_TYPES>;
9191

92+
/** A generic message to display to the user */
93+
message?: string;
94+
9295
/** Message to display to the user */
9396
tooltip?: string;
9497
};

0 commit comments

Comments
 (0)