Skip to content

Commit

Permalink
Fix imports and rename setisDirty
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmoore committed Sep 15, 2024
1 parent 47001e5 commit 0554da1
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const OrderItemsThresholdCustomForm: React.FC< OrderItemsThresholdCustomFormProp
protectionSettingsUI,
setProtectionSettingsUI,
setProtectionSettingsChanged,
setisDirty,
setIsDirty,
} = useContext( FraudPreventionSettingsContext );

const settingUI = useMemo(
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PurchasePriceThresholdCustomForm: React.FC< PurchasePriceThresholdCustomFo
protectionSettingsUI,
setProtectionSettingsUI,
setProtectionSettingsChanged,
setisDirty,
setIsDirty,
} = useContext( FraudPreventionSettingsContext );

const settingUI = useMemo(
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe( 'AVS mismatch card', () => {
setProtectionSettingsUI: setSettings,
protectionSettingsChanged: false,
setProtectionSettingsChanged: jest.fn(),
setisDirty: jest.fn(),
setIsDirty: jest.fn(),
};
const { container } = render(
<FraudPreventionSettingsContext.Provider value={ contextValue }>
Expand Down Expand Up @@ -71,7 +71,7 @@ describe( 'AVS mismatch card', () => {
setProtectionSettingsUI: setSettings,
protectionSettingsChanged: false,
setProtectionSettingsChanged: jest.fn(),
setisDirty: jest.fn(),
setIsDirty: jest.fn(),
};
const { container } = render(
<FraudPreventionSettingsContext.Provider value={ contextValue }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe( 'CVC verification card', () => {
setProtectionSettingsUI: setSettings,
protectionSettingsChanged: false,
setProtectionSettingsChanged: jest.fn(),
setisDirty: jest.fn(),
setIsDirty: jest.fn(),
};
const { container } = render(
<FraudPreventionSettingsContext.Provider value={ contextValue }>
Expand Down Expand Up @@ -74,7 +74,7 @@ describe( 'CVC verification card', () => {
setProtectionSettingsUI: setSettings,
protectionSettingsChanged: false,
setProtectionSettingsChanged: jest.fn(),
setisDirty: jest.fn(),
setIsDirty: jest.fn(),
};
const { container } = render(
<FraudPreventionSettingsContext.Provider value={ contextValue }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FraudPreventionSettingsContext = createContext( {
setProtectionSettingsUI: () => null,
protectionSettingsChanged: false,
setProtectionSettingsChanged: () => false,
setisDirty: () => null,
setIsDirty: () => null,
} as FraudPreventionSettingsContextType );

export default FraudPreventionSettingsContext;
4 changes: 2 additions & 2 deletions client/settings/fraud-protection/advanced-settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -344,7 +344,7 @@ const FraudProtectionAdvancedSettingsPage: React.FC = () => {
setProtectionSettingsUI,
protectionSettingsChanged,
setProtectionSettingsChanged,
setisDirty,
setIsDirty,
} }
>
<SettingsLayout displayBanner={ false }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const FraudProtectionRuleToggle: React.FC< FraudProtectionRuleToggleProps > = (
protectionSettingsUI,
setProtectionSettingsUI,
setProtectionSettingsChanged,
setisDirty,
setIsDirty,
} = useContext( FraudPreventionSettingsContext );

const { isFRTReviewFeatureActive } = wcpaySettings;
Expand Down Expand Up @@ -101,7 +101,7 @@ const FraudProtectionRuleToggle: React.FC< FraudProtectionRuleToggleProps > = (

const handleToggleChange = () => {
setToggleState( ( value ) => ! value );
setisDirty( true );
setIsDirty( true );
};

if ( ! protectionSettingsUI ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const mockContext = {
protectionSettingsChanged: false,
setProtectionSettingsUI: jest.fn(),
setProtectionSettingsChanged: jest.fn(),
setisDirty: jest.fn(),
setIsDirty: jest.fn(),
};

declare const global: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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( () => {
Expand All @@ -58,7 +58,7 @@ describe( 'Fraud protection rule toggle tests', () => {
protectionSettingsChanged: false,
setProtectionSettingsUI: jest.fn(),
setProtectionSettingsChanged: jest.fn(),
setisDirty: jest.fn(),
setIsDirty: jest.fn(),
};
} );

Expand Down
2 changes: 1 addition & 1 deletion client/settings/fraud-protection/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion multi-currency/client/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createContext } from 'react';

const MultiCurrencySettingsContext = createContext( {
isDirty: false,
setisDirty: () => null,
setIsDirty: () => null,
} );

export default MultiCurrencySettingsContext;
4 changes: 2 additions & 2 deletions multi-currency/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const MultiCurrencySettingsPage = () => {
setCurrencyCodeToShowSettingsFor( null );
};

const [ isDirty, setisDirty ] = useState( false );
const [ isDirty, setIsDirty ] = useState( false );

return (
<MultiCurrencySettingsContext.Provider
Expand All @@ -42,7 +42,7 @@ const MultiCurrencySettingsPage = () => {
openSingleCurrencySettings: handleOpenSingleCurrencySettings,
closeSingleCurrencySettings: handleCloseSingleCurrencySettings,
isDirty,
setisDirty,
setIsDirty,
} }
>
{ ! isSingleCurrencyScreenOpen ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -124,7 +124,7 @@ const EnabledCurrenciesModal = ( { className } ) => {
newCurrencies.push( defaultCurrencyCode );
newCurrencies.sort();
submitEnabledCurrenciesUpdate( newCurrencies );
setisDirty( true );
setIsDirty( true );
};

const handleCurrenciesListWidth = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const containerContext = {
openSingleCurrencySettings: jest.fn(),
closeSingleCurrencySettings: jest.fn(),
isDirty: false,
setisDirty: jest.fn(),
setIsDirty: jest.fn(),
};

const getContainer = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 = () => {
Expand All @@ -105,6 +105,7 @@ const StoreSettings = () => {
isStorefrontSwitcherEnabledValue
);
setIsSavingSettings( false );
setIsDirty( false );
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
} ),
};
Expand Down Expand Up @@ -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/,
Expand Down

0 comments on commit 0554da1

Please sign in to comment.