diff --git a/changelog/fix-6497-advanced-fraud-settings-empty b/changelog/fix-6497-advanced-fraud-settings-empty new file mode 100644 index 00000000000..98e38c0b807 --- /dev/null +++ b/changelog/fix-6497-advanced-fraud-settings-empty @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Add notice when no rules are enabled in advanced fraud settings diff --git a/client/settings/fraud-protection/advanced-settings/index.tsx b/client/settings/fraud-protection/advanced-settings/index.tsx index 3c910898159..f18b70a624d 100644 --- a/client/settings/fraud-protection/advanced-settings/index.tsx +++ b/client/settings/fraud-protection/advanced-settings/index.tsx @@ -70,20 +70,28 @@ const observerEventMapping: Record< string, string > = { }; const Breadcrumb = () => ( -
+ { __( + 'At least one risk filter needs to be enabled for advanced protection.', + 'woocommerce-payments' + ) } +
+ > ); const SaveFraudProtectionSettingsButton: React.FC = ( { children } ) => { @@ -154,42 +162,66 @@ const FraudProtectionAdvancedSettingsPage: React.FC = () => { .every( Boolean ); }; + const checkAnyRuleFilterEnabled = ( + settings: ProtectionSettingsUI + ): boolean => { + return Object.values( settings ).some( ( setting ) => setting.enabled ); + }; + const handleSaveSettings = () => { - if ( validateSettings( protectionSettingsUI ) ) { - if ( ProtectionLevel.ADVANCED !== currentProtectionLevel ) { - updateProtectionLevel( ProtectionLevel.ADVANCED ); - dispatch( 'core/notices' ).createSuccessNotice( + if ( ! validateSettings( protectionSettingsUI ) ) { + window.scrollTo( { + top: 0, + } ); + return; + } + + if ( ! checkAnyRuleFilterEnabled( protectionSettingsUI ) ) { + if ( ProtectionLevel.BASIC === currentProtectionLevel ) { + dispatch( 'core/notices' ).createErrorNotice( __( - 'Current protection level is set to "advanced".', + 'At least one risk filter needs to be enabled for advanced protection.', 'woocommerce-payments' ) ); + return; } - const settings = writeRuleset( protectionSettingsUI ); + updateProtectionLevel( ProtectionLevel.BASIC ); + dispatch( 'core/notices' ).createErrorNotice( + __( + 'Current protection level is set to "basic". At least one risk filter needs to be enabled for advanced protection.', + 'woocommerce-payments' + ) + ); + } else if ( ProtectionLevel.ADVANCED !== currentProtectionLevel ) { + updateProtectionLevel( ProtectionLevel.ADVANCED ); + dispatch( 'core/notices' ).createSuccessNotice( + __( + 'Current protection level is set to "advanced".', + 'woocommerce-payments' + ) + ); + } - // Persist the AVS verification setting until the account cache is updated locally. - if ( - wcpaySettings?.accountStatus?.fraudProtection - ?.declineOnAVSFailure - ) { - wcpaySettings.accountStatus.fraudProtection.declineOnAVSFailure = settings.some( - ( setting ) => setting.key === 'avs_verification' - ); - } + const settings = writeRuleset( protectionSettingsUI ); - updateAdvancedFraudProtectionSettings( settings ); + // Persist the AVS verification setting until the account cache is updated locally. + if ( + wcpaySettings?.accountStatus?.fraudProtection?.declineOnAVSFailure + ) { + wcpaySettings.accountStatus.fraudProtection.declineOnAVSFailure = settings.some( + ( setting ) => setting.key === 'avs_verification' + ); + } - saveSettings(); + updateAdvancedFraudProtectionSettings( settings ); - recordEvent( 'wcpay_fraud_protection_advanced_settings_saved', { - settings: JSON.stringify( settings ), - } ); - } else { - window.scrollTo( { - top: 0, - } ); - } + saveSettings(); + + recordEvent( 'wcpay_fraud_protection_advanced_settings_saved', { + settings: JSON.stringify( settings ), + } ); }; // Hack to make "Payments > Settings" the active selected menu item. diff --git a/client/settings/fraud-protection/advanced-settings/test/__snapshots__/index.test.tsx.snap b/client/settings/fraud-protection/advanced-settings/test/__snapshots__/index.test.tsx.snap index abd09b5d4c7..dffbf33c6b1 100644 --- a/client/settings/fraud-protection/advanced-settings/test/__snapshots__/index.test.tsx.snap +++ b/client/settings/fraud-protection/advanced-settings/test/__snapshots__/index.test.tsx.snap @@ -66,6 +66,11 @@ Object { > Advanced fraud protection ++ At least one risk filter needs to be enabled for advanced protection. +
+ At least one risk filter needs to be enabled for advanced protection. +
+ At least one risk filter needs to be enabled for advanced protection. +
+ At least one risk filter needs to be enabled for advanced protection. +
+ At least one risk filter needs to be enabled for advanced protection. +
+ At least one risk filter needs to be enabled for advanced protection. +
+ At least one risk filter needs to be enabled for advanced protection. +
+ At least one risk filter needs to be enabled for advanced protection. +