From 0554da10998d1e220d6ee94211bd20744e3b87da Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Sun, 15 Sep 2024 14:10:20 -0400 Subject: [PATCH] Fix imports and rename setisDirty --- .../advanced-settings/cards/order-items-threshold.tsx | 6 +++--- .../advanced-settings/cards/purchase-price-threshold.tsx | 6 +++--- .../advanced-settings/cards/test/address-mismatch.test.tsx | 2 +- .../advanced-settings/cards/test/avs-mismatch.test.tsx | 4 ++-- .../advanced-settings/cards/test/cvc-verification.test.tsx | 4 ++-- .../cards/test/international-ip-address.test.tsx | 2 +- .../cards/test/ip-address-mismatch.test.tsx | 2 +- .../cards/test/order-items-threshold.test.tsx | 2 +- .../cards/test/purchase-price-threshold.test.tsx | 2 +- .../settings/fraud-protection/advanced-settings/context.ts | 2 +- .../settings/fraud-protection/advanced-settings/index.tsx | 4 ++-- .../fraud-protection/advanced-settings/rule-toggle.tsx | 4 ++-- .../advanced-settings/test/allow-countries-notice.test.tsx | 2 +- .../advanced-settings/test/rule-toggle.test.tsx | 6 +++--- client/settings/fraud-protection/interfaces.ts | 2 +- multi-currency/client/context.js | 2 +- multi-currency/client/index.js | 4 ++-- .../multi-currency/enabled-currencies-list/index.js | 4 ++-- .../multi-currency/enabled-currencies-list/modal.js | 6 +++--- .../multi-currency/enabled-currencies-list/test/index.js | 2 +- .../client/settings/multi-currency/store-settings/index.js | 7 ++++--- .../multi-currency/store-settings/test/index.test.js | 6 +++--- 22 files changed, 41 insertions(+), 40 deletions(-) diff --git a/client/settings/fraud-protection/advanced-settings/cards/order-items-threshold.tsx b/client/settings/fraud-protection/advanced-settings/cards/order-items-threshold.tsx index ef862bf1299..31b4c7be8b6 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/order-items-threshold.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/order-items-threshold.tsx @@ -37,7 +37,7 @@ const OrderItemsThresholdCustomForm: React.FC< OrderItemsThresholdCustomFormProp protectionSettingsUI, setProtectionSettingsUI, setProtectionSettingsChanged, - setisDirty, + setIsDirty, } = useContext( FraudPreventionSettingsContext ); const settingUI = useMemo( @@ -100,7 +100,7 @@ const OrderItemsThresholdCustomForm: React.FC< OrderItemsThresholdCustomFormProp type="number" onChange={ ( value ) => { setMinItemsCount( value ); - setisDirty( true ); + setIsDirty( true ); } } onKeyDown={ ( e ) => /^[+-.,e]$/m.test( e.key ) && e.preventDefault() @@ -127,7 +127,7 @@ const OrderItemsThresholdCustomForm: React.FC< OrderItemsThresholdCustomFormProp value={ maxItemsCount } onChange={ ( value ) => { setMaxItemsCount( value ); - setisDirty( true ); + setIsDirty( true ); } } onKeyDown={ ( e ) => /^[+-.,e]$/m.test( e.key ) && e.preventDefault() diff --git a/client/settings/fraud-protection/advanced-settings/cards/purchase-price-threshold.tsx b/client/settings/fraud-protection/advanced-settings/cards/purchase-price-threshold.tsx index 98acc7da9d6..59bd205a45c 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/purchase-price-threshold.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/purchase-price-threshold.tsx @@ -56,7 +56,7 @@ const PurchasePriceThresholdCustomForm: React.FC< PurchasePriceThresholdCustomFo protectionSettingsUI, setProtectionSettingsUI, setProtectionSettingsChanged, - setisDirty, + setIsDirty, } = useContext( FraudPreventionSettingsContext ); const settingUI = useMemo( @@ -114,7 +114,7 @@ const PurchasePriceThresholdCustomForm: React.FC< PurchasePriceThresholdCustomFo value={ minAmount.toString() } onChange={ ( val ) => { setMinAmount( Number( val ) ); - setisDirty( true ); + setIsDirty( true ); } } help={ __( 'Leave blank for no limit', @@ -136,7 +136,7 @@ const PurchasePriceThresholdCustomForm: React.FC< PurchasePriceThresholdCustomFo value={ maxAmount.toString() } onChange={ ( val ) => { setMaxAmount( Number( val ) ); - setisDirty( true ); + setIsDirty( true ); } } help={ __( 'Leave blank for no limit', diff --git a/client/settings/fraud-protection/advanced-settings/cards/test/address-mismatch.test.tsx b/client/settings/fraud-protection/advanced-settings/cards/test/address-mismatch.test.tsx index 054fd450c7c..8162cd07f1b 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/test/address-mismatch.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/test/address-mismatch.test.tsx @@ -34,7 +34,7 @@ describe( 'Address mismatch card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; test( 'renders correctly', () => { settings.address_mismatch.enabled = false; diff --git a/client/settings/fraud-protection/advanced-settings/cards/test/avs-mismatch.test.tsx b/client/settings/fraud-protection/advanced-settings/cards/test/avs-mismatch.test.tsx index c5b3e17f966..b2ae2de8e27 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/test/avs-mismatch.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/test/avs-mismatch.test.tsx @@ -42,7 +42,7 @@ describe( 'AVS mismatch card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; const { container } = render( @@ -71,7 +71,7 @@ describe( 'AVS mismatch card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; const { container } = render( diff --git a/client/settings/fraud-protection/advanced-settings/cards/test/cvc-verification.test.tsx b/client/settings/fraud-protection/advanced-settings/cards/test/cvc-verification.test.tsx index 72827bb5b54..dfbbbc47ad5 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/test/cvc-verification.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/test/cvc-verification.test.tsx @@ -42,7 +42,7 @@ describe( 'CVC verification card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; const { container } = render( @@ -74,7 +74,7 @@ describe( 'CVC verification card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; const { container } = render( diff --git a/client/settings/fraud-protection/advanced-settings/cards/test/international-ip-address.test.tsx b/client/settings/fraud-protection/advanced-settings/cards/test/international-ip-address.test.tsx index 134b3d2be77..6a36f94b4ee 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/test/international-ip-address.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/test/international-ip-address.test.tsx @@ -44,7 +44,7 @@ describe( 'International IP address card', () => { protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), isDirty: false, - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; global.wcSettings = { admin: { diff --git a/client/settings/fraud-protection/advanced-settings/cards/test/ip-address-mismatch.test.tsx b/client/settings/fraud-protection/advanced-settings/cards/test/ip-address-mismatch.test.tsx index 944d3ca11cf..b102364ad75 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/test/ip-address-mismatch.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/test/ip-address-mismatch.test.tsx @@ -40,7 +40,7 @@ describe( 'International billing address card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; global.wcSettings = { admin: { diff --git a/client/settings/fraud-protection/advanced-settings/cards/test/order-items-threshold.test.tsx b/client/settings/fraud-protection/advanced-settings/cards/test/order-items-threshold.test.tsx index 5e80bfe562f..268845ba776 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/test/order-items-threshold.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/test/order-items-threshold.test.tsx @@ -39,7 +39,7 @@ describe( 'Order items threshold card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; test( 'renders correctly', () => { const { container } = render( diff --git a/client/settings/fraud-protection/advanced-settings/cards/test/purchase-price-threshold.test.tsx b/client/settings/fraud-protection/advanced-settings/cards/test/purchase-price-threshold.test.tsx index 94e317e2d06..23f12a04d51 100644 --- a/client/settings/fraud-protection/advanced-settings/cards/test/purchase-price-threshold.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/cards/test/purchase-price-threshold.test.tsx @@ -67,7 +67,7 @@ describe( 'Purchase price threshold card', () => { setProtectionSettingsUI: setSettings, protectionSettingsChanged: false, setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; test( 'renders correctly', () => { const { container } = render( diff --git a/client/settings/fraud-protection/advanced-settings/context.ts b/client/settings/fraud-protection/advanced-settings/context.ts index a14394de235..aa708fa36d0 100644 --- a/client/settings/fraud-protection/advanced-settings/context.ts +++ b/client/settings/fraud-protection/advanced-settings/context.ts @@ -9,7 +9,7 @@ const FraudPreventionSettingsContext = createContext( { setProtectionSettingsUI: () => null, protectionSettingsChanged: false, setProtectionSettingsChanged: () => false, - setisDirty: () => null, + setIsDirty: () => null, } as FraudPreventionSettingsContextType ); export default FraudPreventionSettingsContext; diff --git a/client/settings/fraud-protection/advanced-settings/index.tsx b/client/settings/fraud-protection/advanced-settings/index.tsx index 961938ebaa9..881a09fdb90 100644 --- a/client/settings/fraud-protection/advanced-settings/index.tsx +++ b/client/settings/fraud-protection/advanced-settings/index.tsx @@ -102,7 +102,7 @@ const SaveFraudProtectionSettingsButton: React.FC = ( { children } ) => { }; const FraudProtectionAdvancedSettingsPage: React.FC = () => { - const [ isDirty, setisDirty ] = useState( false ); + const [ isDirty, setIsDirty ] = useState( false ); const { saveSettings, isLoading, isSaving } = useSettings() as SettingsHook; @@ -344,7 +344,7 @@ const FraudProtectionAdvancedSettingsPage: React.FC = () => { setProtectionSettingsUI, protectionSettingsChanged, setProtectionSettingsChanged, - setisDirty, + setIsDirty, } } > diff --git a/client/settings/fraud-protection/advanced-settings/rule-toggle.tsx b/client/settings/fraud-protection/advanced-settings/rule-toggle.tsx index faa61254b67..85e32790595 100644 --- a/client/settings/fraud-protection/advanced-settings/rule-toggle.tsx +++ b/client/settings/fraud-protection/advanced-settings/rule-toggle.tsx @@ -58,7 +58,7 @@ const FraudProtectionRuleToggle: React.FC< FraudProtectionRuleToggleProps > = ( protectionSettingsUI, setProtectionSettingsUI, setProtectionSettingsChanged, - setisDirty, + setIsDirty, } = useContext( FraudPreventionSettingsContext ); const { isFRTReviewFeatureActive } = wcpaySettings; @@ -101,7 +101,7 @@ const FraudProtectionRuleToggle: React.FC< FraudProtectionRuleToggleProps > = ( const handleToggleChange = () => { setToggleState( ( value ) => ! value ); - setisDirty( true ); + setIsDirty( true ); }; if ( ! protectionSettingsUI ) { diff --git a/client/settings/fraud-protection/advanced-settings/test/allow-countries-notice.test.tsx b/client/settings/fraud-protection/advanced-settings/test/allow-countries-notice.test.tsx index 8c021d7951a..c503bf74ed7 100644 --- a/client/settings/fraud-protection/advanced-settings/test/allow-countries-notice.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/test/allow-countries-notice.test.tsx @@ -19,7 +19,7 @@ const mockContext = { protectionSettingsChanged: false, setProtectionSettingsUI: jest.fn(), setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; declare const global: { diff --git a/client/settings/fraud-protection/advanced-settings/test/rule-toggle.test.tsx b/client/settings/fraud-protection/advanced-settings/test/rule-toggle.test.tsx index 45e63a83983..d2476015479 100644 --- a/client/settings/fraud-protection/advanced-settings/test/rule-toggle.test.tsx +++ b/client/settings/fraud-protection/advanced-settings/test/rule-toggle.test.tsx @@ -26,7 +26,7 @@ interface mockContext { protectionSettingsChanged: boolean; setProtectionSettingsUI: jest.Mock; setProtectionSettingsChanged: jest.Mock; - setisDirty: jest.Mock; + setIsDirty: jest.Mock; } describe( 'Fraud protection rule toggle tests', () => { @@ -44,7 +44,7 @@ describe( 'Fraud protection rule toggle tests', () => { protectionSettingsChanged: false, setProtectionSettingsUI: jest.fn(), setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; beforeEach( () => { @@ -58,7 +58,7 @@ describe( 'Fraud protection rule toggle tests', () => { protectionSettingsChanged: false, setProtectionSettingsUI: jest.fn(), setProtectionSettingsChanged: jest.fn(), - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; } ); diff --git a/client/settings/fraud-protection/interfaces.ts b/client/settings/fraud-protection/interfaces.ts index e60b604a896..7ad040bad87 100644 --- a/client/settings/fraud-protection/interfaces.ts +++ b/client/settings/fraud-protection/interfaces.ts @@ -36,7 +36,7 @@ export interface FraudPreventionSettingsContextType { setProtectionSettingsUI: ( settings: ProtectionSettingsUI ) => void; protectionSettingsChanged: boolean; setProtectionSettingsChanged: Dispatch< SetStateAction< boolean > >; - setisDirty: Dispatch< SetStateAction< boolean > >; + setIsDirty: Dispatch< SetStateAction< boolean > >; } export interface FraudProtectionSettingsSingleCheck { diff --git a/multi-currency/client/context.js b/multi-currency/client/context.js index baca9094e52..531f8324395 100644 --- a/multi-currency/client/context.js +++ b/multi-currency/client/context.js @@ -7,7 +7,7 @@ import { createContext } from 'react'; const MultiCurrencySettingsContext = createContext( { isDirty: false, - setisDirty: () => null, + setIsDirty: () => null, } ); export default MultiCurrencySettingsContext; diff --git a/multi-currency/client/index.js b/multi-currency/client/index.js index b5cdf1c4760..befe544fa3b 100644 --- a/multi-currency/client/index.js +++ b/multi-currency/client/index.js @@ -32,7 +32,7 @@ const MultiCurrencySettingsPage = () => { setCurrencyCodeToShowSettingsFor( null ); }; - const [ isDirty, setisDirty ] = useState( false ); + const [ isDirty, setIsDirty ] = useState( false ); return ( { openSingleCurrencySettings: handleOpenSingleCurrencySettings, closeSingleCurrencySettings: handleCloseSingleCurrencySettings, isDirty, - setisDirty, + setIsDirty, } } > { ! isSingleCurrencyScreenOpen ? ( diff --git a/multi-currency/client/settings/multi-currency/enabled-currencies-list/index.js b/multi-currency/client/settings/multi-currency/enabled-currencies-list/index.js index e6f46981b0a..78522be1256 100644 --- a/multi-currency/client/settings/multi-currency/enabled-currencies-list/index.js +++ b/multi-currency/client/settings/multi-currency/enabled-currencies-list/index.js @@ -67,13 +67,13 @@ const EnabledCurrencies = () => { } = useEnabledCurrencies(); const classBase = 'wcpay-multi-currency'; - const { setisDirty } = useContext( MultiCurrencySettingsContext ); + const { setIsDirty } = useContext( MultiCurrencySettingsContext ); const handleDeleteClick = ( code ) => { const newCurrencies = Object.keys( enabledCurrencies ); newCurrencies.splice( newCurrencies.indexOf( code ), 1 ); submitEnabledCurrenciesUpdate( newCurrencies ); - setisDirty( true ); + setIsDirty( true ); }; const enabledKeys = enabledCurrencies diff --git a/multi-currency/client/settings/multi-currency/enabled-currencies-list/modal.js b/multi-currency/client/settings/multi-currency/enabled-currencies-list/modal.js index 7e9aec050a0..ea650cfdcec 100644 --- a/multi-currency/client/settings/multi-currency/enabled-currencies-list/modal.js +++ b/multi-currency/client/settings/multi-currency/enabled-currencies-list/modal.js @@ -25,12 +25,12 @@ import EnabledCurrenciesModalCheckbox from './modal-checkbox'; import { ConfirmationModal } from 'multi-currency/interface/components'; import Search from 'multi-currency/components/search'; import './style.scss'; -import MultiCurrencySettingsContext from '../../context'; +import MultiCurrencySettingsContext from 'multi-currency/context'; // TODO: This works when saving, but list does not refresh. // TODO: Should we reset selected currencies on modal close? const EnabledCurrenciesModal = ( { className } ) => { - const { setisDirty } = useContext( MultiCurrencySettingsContext ); + const { setIsDirty } = useContext( MultiCurrencySettingsContext ); const availableCurrencies = useAvailableCurrencies(); const availableCurrencyCodes = Object.keys( availableCurrencies ); @@ -124,7 +124,7 @@ const EnabledCurrenciesModal = ( { className } ) => { newCurrencies.push( defaultCurrencyCode ); newCurrencies.sort(); submitEnabledCurrenciesUpdate( newCurrencies ); - setisDirty( true ); + setIsDirty( true ); }; const handleCurrenciesListWidth = () => { diff --git a/multi-currency/client/settings/multi-currency/enabled-currencies-list/test/index.js b/multi-currency/client/settings/multi-currency/enabled-currencies-list/test/index.js index 26a4e17bc77..e2fbba45fbd 100644 --- a/multi-currency/client/settings/multi-currency/enabled-currencies-list/test/index.js +++ b/multi-currency/client/settings/multi-currency/enabled-currencies-list/test/index.js @@ -191,7 +191,7 @@ const containerContext = { openSingleCurrencySettings: jest.fn(), closeSingleCurrencySettings: jest.fn(), isDirty: false, - setisDirty: jest.fn(), + setIsDirty: jest.fn(), }; const getContainer = () => { diff --git a/multi-currency/client/settings/multi-currency/store-settings/index.js b/multi-currency/client/settings/multi-currency/store-settings/index.js index af99153c37f..9f3982f33af 100644 --- a/multi-currency/client/settings/multi-currency/store-settings/index.js +++ b/multi-currency/client/settings/multi-currency/store-settings/index.js @@ -71,7 +71,7 @@ const StoreSettings = () => { const [ isPreviewModalOpen, setPreviewModalOpen ] = useState( false ); - const { isDirty, setisDirty } = useContext( MultiCurrencySettingsContext ); + const { isDirty, setIsDirty } = useContext( MultiCurrencySettingsContext ); useEffect( () => { if ( Object.keys( storeSettings ).length ) { @@ -90,12 +90,12 @@ const StoreSettings = () => { const handleIsAutomaticSwitchEnabledClick = ( value ) => { setIsAutomaticSwitchEnabledValue( value ); - setisDirty( true ); + setIsDirty( true ); }; const handleIsStorefrontSwitcherEnabledClick = ( value ) => { setIsStorefrontSwitcherEnabledValue( value ); - setisDirty( true ); + setIsDirty( true ); }; const saveSettings = () => { @@ -105,6 +105,7 @@ const StoreSettings = () => { isStorefrontSwitcherEnabledValue ); setIsSavingSettings( false ); + setIsDirty( false ); }; return ( diff --git a/multi-currency/client/settings/multi-currency/store-settings/test/index.test.js b/multi-currency/client/settings/multi-currency/store-settings/test/index.test.js index 8a4f5555387..b963d785a62 100644 --- a/multi-currency/client/settings/multi-currency/store-settings/test/index.test.js +++ b/multi-currency/client/settings/multi-currency/store-settings/test/index.test.js @@ -9,7 +9,7 @@ import { render, screen, fireEvent } from '@testing-library/react'; */ import { useStoreSettings } from 'multi-currency/data'; import StoreSettings from '..'; -import MultiCurrencySettingsContext from '../../../context'; +import MultiCurrencySettingsContext from 'multi-currency/context'; jest.mock( 'multi-currency/data', () => ( { useStoreSettings: jest.fn(), @@ -21,7 +21,7 @@ const containerContext = { openSingleCurrencySettings: jest.fn(), closeSingleCurrencySettings: jest.fn(), isDirty: false, - setisDirty: jest.fn().mockImplementation( ( value ) => { + setIsDirty: jest.fn().mockImplementation( ( value ) => { containerContext.isDirty = value; } ), }; @@ -79,7 +79,7 @@ describe( 'Multi-Currency store settings', () => { test( 'store settings are saved with continue button click', () => { createContainer(); const { submitStoreSettingsUpdate } = useStoreSettings(); - containerContext.setisDirty( true ); + containerContext.setIsDirty( true ); fireEvent.click( screen.getByRole( 'button', { name: /Save changes/,