Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566)
* Remove mixed tabs and spaces in tsconfig.json * Update formatting in json files * Upgrade wp-prettier to 2.6.2
This commit is contained in:
parent
0dfc1ad58b
commit
521f93619b
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"default": true,
|
"default": true,
|
||||||
"MD003": { "style": "atx" },
|
"MD003": { "style": "atx" },
|
||||||
|
@ -9,7 +7,7 @@
|
||||||
"MD025": false,
|
"MD025": false,
|
||||||
"MD029": false,
|
"MD029": false,
|
||||||
"MD033": false,
|
"MD033": false,
|
||||||
"MD046": {"style": "fenced"},
|
"MD046": { "style": "fenced" },
|
||||||
"no-hard-tabs": false,
|
"no-hard-tabs": false,
|
||||||
"whitespace": false
|
"whitespace": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,8 @@ const Block = ( { className, showFormElements } ) => {
|
||||||
className,
|
className,
|
||||||
'wc-block-components-product-add-to-cart',
|
'wc-block-components-product-add-to-cart',
|
||||||
{
|
{
|
||||||
'wc-block-components-product-add-to-cart--placeholder': isEmpty(
|
'wc-block-components-product-add-to-cart--placeholder':
|
||||||
product
|
isEmpty( product ),
|
||||||
),
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,8 @@ const AttributeSelectControl = ( {
|
||||||
'woo-gutenberg-products-block'
|
'woo-gutenberg-products-block'
|
||||||
),
|
),
|
||||||
} ) => {
|
} ) => {
|
||||||
const {
|
const { getValidationError, setValidationErrors, clearValidationError } =
|
||||||
getValidationError,
|
useValidationContext();
|
||||||
setValidationErrors,
|
|
||||||
clearValidationError,
|
|
||||||
} = useValidationContext();
|
|
||||||
const errorId = attributeName;
|
const errorId = attributeName;
|
||||||
const error = getValidationError( errorId ) || {};
|
const error = getValidationError( errorId ) || {};
|
||||||
|
|
||||||
|
@ -60,10 +57,10 @@ const AttributeSelectControl = ( {
|
||||||
] );
|
] );
|
||||||
|
|
||||||
// Remove validation errors when unmounted.
|
// Remove validation errors when unmounted.
|
||||||
useEffect( () => () => void clearValidationError( errorId ), [
|
useEffect(
|
||||||
errorId,
|
() => () => void clearValidationError( errorId ),
|
||||||
clearValidationError,
|
[ errorId, clearValidationError ]
|
||||||
] );
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="wc-block-components-product-add-to-cart-attribute-picker__container">
|
<div className="wc-block-components-product-add-to-cart-attribute-picker__container">
|
||||||
|
|
|
@ -45,7 +45,8 @@ const AddToCartButton = () => {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
const unsubscribeProcessing = eventRegistration.onAddToCartAfterProcessingWithSuccess(
|
const unsubscribeProcessing =
|
||||||
|
eventRegistration.onAddToCartAfterProcessingWithSuccess(
|
||||||
onSuccess,
|
onSuccess,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
|
@ -52,7 +52,8 @@ const Block = ( props ) => {
|
||||||
'wp-block-button',
|
'wp-block-button',
|
||||||
'wc-block-components-product-button',
|
'wc-block-components-product-button',
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-add-to-cart` ]: parentClassName,
|
[ `${ parentClassName }__product-add-to-cart` ]:
|
||||||
|
parentClassName,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
>
|
>
|
||||||
|
|
|
@ -49,7 +49,8 @@ const Block = ( props: Props ): JSX.Element | null => {
|
||||||
'wc-block-components-product-category-list',
|
'wc-block-components-product-category-list',
|
||||||
colorProps.className,
|
colorProps.className,
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-category-list` ]: parentClassName,
|
[ `${ parentClassName }__product-category-list` ]:
|
||||||
|
parentClassName,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
style={ { ...colorProps.style, ...typographyProps.style } }
|
style={ { ...colorProps.style, ...typographyProps.style } }
|
||||||
|
|
|
@ -60,7 +60,8 @@ export const Block = ( props ) => {
|
||||||
className,
|
className,
|
||||||
'wc-block-components-product-image',
|
'wc-block-components-product-image',
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-image` ]: parentClassName,
|
[ `${ parentClassName }__product-image` ]:
|
||||||
|
parentClassName,
|
||||||
},
|
},
|
||||||
borderProps.className
|
borderProps.className
|
||||||
) }
|
) }
|
||||||
|
|
|
@ -23,12 +23,8 @@ import withProductSelector from '../shared/with-product-selector';
|
||||||
import { BLOCK_TITLE, BLOCK_ICON } from './constants';
|
import { BLOCK_TITLE, BLOCK_ICON } from './constants';
|
||||||
|
|
||||||
const Edit = ( { attributes, setAttributes } ) => {
|
const Edit = ( { attributes, setAttributes } ) => {
|
||||||
const {
|
const { showProductLink, imageSizing, showSaleBadge, saleBadgeAlign } =
|
||||||
showProductLink,
|
attributes;
|
||||||
imageSizing,
|
|
||||||
showSaleBadge,
|
|
||||||
saleBadgeAlign,
|
|
||||||
} = attributes;
|
|
||||||
|
|
||||||
const blockProps = useBlockProps();
|
const blockProps = useBlockProps();
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,7 @@ const productWithImages = {
|
||||||
id: 56,
|
id: 56,
|
||||||
src: 'logo-1.jpg',
|
src: 'logo-1.jpg',
|
||||||
thumbnail: 'logo-1-324x324.jpg',
|
thumbnail: 'logo-1-324x324.jpg',
|
||||||
srcset:
|
srcset: 'logo-1.jpg 800w, logo-1-300x300.jpg 300w, logo-1-150x150.jpg 150w, logo-1-768x767.jpg 768w, logo-1-324x324.jpg 324w, logo-1-416x415.jpg 416w, logo-1-100x100.jpg 100w',
|
||||||
'logo-1.jpg 800w, logo-1-300x300.jpg 300w, logo-1-150x150.jpg 150w, logo-1-768x767.jpg 768w, logo-1-324x324.jpg 324w, logo-1-416x415.jpg 416w, logo-1-100x100.jpg 100w',
|
|
||||||
sizes: '(max-width: 800px) 100vw, 800px',
|
sizes: '(max-width: 800px) 100vw, 800px',
|
||||||
name: 'logo-1.jpg',
|
name: 'logo-1.jpg',
|
||||||
alt: '',
|
alt: '',
|
||||||
|
@ -56,8 +55,7 @@ const productWithImages = {
|
||||||
id: 55,
|
id: 55,
|
||||||
src: 'beanie-with-logo-1.jpg',
|
src: 'beanie-with-logo-1.jpg',
|
||||||
thumbnail: 'beanie-with-logo-1-324x324.jpg',
|
thumbnail: 'beanie-with-logo-1-324x324.jpg',
|
||||||
srcset:
|
srcset: 'beanie-with-logo-1.jpg 800w, beanie-with-logo-1-300x300.jpg 300w, beanie-with-logo-1-150x150.jpg 150w, beanie-with-logo-1-768x768.jpg 768w, beanie-with-logo-1-324x324.jpg 324w, beanie-with-logo-1-416x416.jpg 416w, beanie-with-logo-1-100x100.jpg 100w',
|
||||||
'beanie-with-logo-1.jpg 800w, beanie-with-logo-1-300x300.jpg 300w, beanie-with-logo-1-150x150.jpg 150w, beanie-with-logo-1-768x768.jpg 768w, beanie-with-logo-1-324x324.jpg 324w, beanie-with-logo-1-416x416.jpg 416w, beanie-with-logo-1-100x100.jpg 100w',
|
|
||||||
sizes: '(max-width: 800px) 100vw, 800px',
|
sizes: '(max-width: 800px) 100vw, 800px',
|
||||||
name: 'beanie-with-logo-1.jpg',
|
name: 'beanie-with-logo-1.jpg',
|
||||||
alt: '',
|
alt: '',
|
||||||
|
|
|
@ -79,7 +79,8 @@ const Block = ( props ) => {
|
||||||
// This is the regular or original price when the `price` value is a sale price.
|
// This is the regular or original price when the `price` value is a sale price.
|
||||||
regularPrice={ prices.regular_price }
|
regularPrice={ prices.regular_price }
|
||||||
regularPriceClassName={ classnames( {
|
regularPriceClassName={ classnames( {
|
||||||
[ `${ parentClassName }__product-price__regular` ]: parentClassName,
|
[ `${ parentClassName }__product-price__regular` ]:
|
||||||
|
parentClassName,
|
||||||
} ) }
|
} ) }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -48,11 +48,16 @@ const Block = ( props ) => {
|
||||||
colorProps.className,
|
colorProps.className,
|
||||||
'wc-block-components-product-stock-indicator',
|
'wc-block-components-product-stock-indicator',
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__stock-indicator` ]: parentClassName,
|
[ `${ parentClassName }__stock-indicator` ]:
|
||||||
'wc-block-components-product-stock-indicator--in-stock': inStock,
|
parentClassName,
|
||||||
'wc-block-components-product-stock-indicator--out-of-stock': ! inStock,
|
'wc-block-components-product-stock-indicator--in-stock':
|
||||||
'wc-block-components-product-stock-indicator--low-stock': !! lowStock,
|
inStock,
|
||||||
'wc-block-components-product-stock-indicator--available-on-backorder': !! isBackordered,
|
'wc-block-components-product-stock-indicator--out-of-stock':
|
||||||
|
! inStock,
|
||||||
|
'wc-block-components-product-stock-indicator--low-stock':
|
||||||
|
!! lowStock,
|
||||||
|
'wc-block-components-product-stock-indicator--available-on-backorder':
|
||||||
|
!! isBackordered,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
style={ { ...colorProps.style, ...typographyProps.style } }
|
style={ { ...colorProps.style, ...typographyProps.style } }
|
||||||
|
|
|
@ -43,7 +43,8 @@ const Block = ( props ) => {
|
||||||
className,
|
className,
|
||||||
`wc-block-components-product-summary`,
|
`wc-block-components-product-summary`,
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-summary` ]: parentClassName,
|
[ `${ parentClassName }__product-summary` ]:
|
||||||
|
parentClassName,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
/>
|
/>
|
||||||
|
@ -65,7 +66,8 @@ const Block = ( props ) => {
|
||||||
colorProps.className,
|
colorProps.className,
|
||||||
`wc-block-components-product-summary`,
|
`wc-block-components-product-summary`,
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-summary` ]: parentClassName,
|
[ `${ parentClassName }__product-summary` ]:
|
||||||
|
parentClassName,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
source={ source }
|
source={ source }
|
||||||
|
|
|
@ -45,7 +45,8 @@ const Block = ( props ) => {
|
||||||
colorProps.className,
|
colorProps.className,
|
||||||
'wc-block-components-product-tag-list',
|
'wc-block-components-product-tag-list',
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-tag-list` ]: parentClassName,
|
[ `${ parentClassName }__product-tag-list` ]:
|
||||||
|
parentClassName,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
style={ { ...colorProps.style, ...typographyProps.style } }
|
style={ { ...colorProps.style, ...typographyProps.style } }
|
||||||
|
|
|
@ -33,7 +33,8 @@ interface TagNameProps extends HTMLAttributes< HTMLOrSVGElement > {
|
||||||
const TagName = ( {
|
const TagName = ( {
|
||||||
children,
|
children,
|
||||||
headingLevel,
|
headingLevel,
|
||||||
elementType: ElementType = `h${ headingLevel }` as keyof JSX.IntrinsicElements,
|
elementType:
|
||||||
|
ElementType = `h${ headingLevel }` as keyof JSX.IntrinsicElements,
|
||||||
...props
|
...props
|
||||||
}: TagNameProps ): JSX.Element => {
|
}: TagNameProps ): JSX.Element => {
|
||||||
return <ElementType { ...props }>{ children }</ElementType>;
|
return <ElementType { ...props }>{ children }</ElementType>;
|
||||||
|
@ -77,7 +78,8 @@ export const Block = ( props: Props ): JSX.Element => {
|
||||||
colorProps.className,
|
colorProps.className,
|
||||||
'wc-block-components-product-title',
|
'wc-block-components-product-title',
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-title` ]: parentClassName,
|
[ `${ parentClassName }__product-title` ]:
|
||||||
|
parentClassName,
|
||||||
[ `wc-block-components-product-title--align-${ align }` ]:
|
[ `wc-block-components-product-title--align-${ align }` ]:
|
||||||
align && isFeaturePluginBuild(),
|
align && isFeaturePluginBuild(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,20 +78,17 @@ interface AddressFormProps {
|
||||||
*/
|
*/
|
||||||
const AddressForm = ( {
|
const AddressForm = ( {
|
||||||
id = '',
|
id = '',
|
||||||
fields = ( Object.keys(
|
fields = Object.keys(
|
||||||
defaultAddressFields
|
defaultAddressFields
|
||||||
) as unknown ) as ( keyof AddressFields )[],
|
) as unknown as ( keyof AddressFields )[],
|
||||||
fieldConfig = {} as Record< keyof AddressFields, Partial< AddressField > >,
|
fieldConfig = {} as Record< keyof AddressFields, Partial< AddressField > >,
|
||||||
instanceId,
|
instanceId,
|
||||||
onChange,
|
onChange,
|
||||||
type = 'shipping',
|
type = 'shipping',
|
||||||
values,
|
values,
|
||||||
}: AddressFormProps ): JSX.Element => {
|
}: AddressFormProps ): JSX.Element => {
|
||||||
const {
|
const { getValidationError, setValidationErrors, clearValidationError } =
|
||||||
getValidationError,
|
useValidationContext();
|
||||||
setValidationErrors,
|
|
||||||
clearValidationError,
|
|
||||||
} = useValidationContext();
|
|
||||||
|
|
||||||
const currentFields = useShallowEqual( fields );
|
const currentFields = useShallowEqual( fields );
|
||||||
|
|
||||||
|
|
|
@ -81,11 +81,8 @@ const inputAddress = async ( {
|
||||||
|
|
||||||
describe( 'AddressForm Component', () => {
|
describe( 'AddressForm Component', () => {
|
||||||
const WrappedAddressForm = ( { type } ) => {
|
const WrappedAddressForm = ( { type } ) => {
|
||||||
const {
|
const { defaultAddressFields, setShippingAddress, shippingAddress } =
|
||||||
defaultAddressFields,
|
useCheckoutAddress();
|
||||||
setShippingAddress,
|
|
||||||
shippingAddress,
|
|
||||||
} = useCheckoutAddress();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AddressForm
|
<AddressForm
|
||||||
|
|
|
@ -64,7 +64,8 @@ const FormStep = ( {
|
||||||
className,
|
className,
|
||||||
'wc-block-components-checkout-step',
|
'wc-block-components-checkout-step',
|
||||||
{
|
{
|
||||||
'wc-block-components-checkout-step--with-step-number': showStepNumber,
|
'wc-block-components-checkout-step--with-step-number':
|
||||||
|
showStepNumber,
|
||||||
'wc-block-components-checkout-step--disabled': disabled,
|
'wc-block-components-checkout-step--disabled': disabled,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
|
|
|
@ -25,10 +25,8 @@ const ShippingCalculatorAddress = ( {
|
||||||
addressFields,
|
addressFields,
|
||||||
}: ShippingCalculatorAddressProps ): JSX.Element => {
|
}: ShippingCalculatorAddressProps ): JSX.Element => {
|
||||||
const [ address, setAddress ] = useState( initialAddress );
|
const [ address, setAddress ] = useState( initialAddress );
|
||||||
const {
|
const { hasValidationErrors, showAllValidationErrors } =
|
||||||
hasValidationErrors,
|
useValidationContext();
|
||||||
showAllValidationErrors,
|
|
||||||
} = useValidationContext();
|
|
||||||
|
|
||||||
const validateSubmit = () => {
|
const validateSubmit = () => {
|
||||||
showAllValidationErrors();
|
showAllValidationErrors();
|
||||||
|
|
|
@ -62,12 +62,8 @@ const PackageRates = ( {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const { label, secondaryLabel, description, secondaryDescription } =
|
||||||
label,
|
renderOption( rates[ 0 ] );
|
||||||
secondaryLabel,
|
|
||||||
description,
|
|
||||||
secondaryDescription,
|
|
||||||
} = renderOption( rates[ 0 ] );
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RadioControlOptionLayout
|
<RadioControlOptionLayout
|
||||||
|
|
|
@ -21,8 +21,7 @@ const NZD: Currency = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title:
|
title: 'WooCommerce Blocks/@base-components/cart-checkout/totals/FooterItem',
|
||||||
'WooCommerce Blocks/@base-components/cart-checkout/totals/FooterItem',
|
|
||||||
component: FooterItem,
|
component: FooterItem,
|
||||||
args: {
|
args: {
|
||||||
currency: NZD,
|
currency: NZD,
|
||||||
|
|
|
@ -131,9 +131,8 @@ export const TotalsShipping = ( {
|
||||||
isCheckout = false,
|
isCheckout = false,
|
||||||
className,
|
className,
|
||||||
}: TotalShippingProps ): ReactElement => {
|
}: TotalShippingProps ): ReactElement => {
|
||||||
const [ isShippingCalculatorOpen, setIsShippingCalculatorOpen ] = useState(
|
const [ isShippingCalculatorOpen, setIsShippingCalculatorOpen ] =
|
||||||
false
|
useState( false );
|
||||||
);
|
|
||||||
const {
|
const {
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
cartHasCalculatedShipping,
|
cartHasCalculatedShipping,
|
||||||
|
|
|
@ -55,11 +55,8 @@ const Combobox = ( {
|
||||||
instanceId = '0',
|
instanceId = '0',
|
||||||
autoComplete = 'off',
|
autoComplete = 'off',
|
||||||
}: ComboboxProps ): JSX.Element => {
|
}: ComboboxProps ): JSX.Element => {
|
||||||
const {
|
const { getValidationError, setValidationErrors, clearValidationError } =
|
||||||
getValidationError,
|
useValidationContext();
|
||||||
setValidationErrors,
|
|
||||||
clearValidationError,
|
|
||||||
} = useValidationContext();
|
|
||||||
|
|
||||||
const controlRef = useRef< HTMLDivElement >( null );
|
const controlRef = useRef< HTMLDivElement >( null );
|
||||||
const controlId = id || 'control-' + instanceId;
|
const controlId = id || 'control-' + instanceId;
|
||||||
|
@ -126,7 +123,8 @@ const Combobox = ( {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to match.
|
// Try to match.
|
||||||
const normalizedFilterValue = filterValue.toLocaleUpperCase();
|
const normalizedFilterValue =
|
||||||
|
filterValue.toLocaleUpperCase();
|
||||||
const foundOption = options.find(
|
const foundOption = options.find(
|
||||||
( option ) =>
|
( option ) =>
|
||||||
option.label
|
option.label
|
||||||
|
|
|
@ -64,7 +64,8 @@ export const CountryInput = ( {
|
||||||
autoComplete={ autoComplete }
|
autoComplete={ autoComplete }
|
||||||
value={ value }
|
value={ value }
|
||||||
onChange={ ( event ) => {
|
onChange={ ( event ) => {
|
||||||
const textValue = event.target.value.toLocaleUpperCase();
|
const textValue =
|
||||||
|
event.target.value.toLocaleUpperCase();
|
||||||
const foundOption = options.find(
|
const foundOption = options.find(
|
||||||
( option ) =>
|
( option ) =>
|
||||||
( textValue.length !== 2 &&
|
( textValue.length !== 2 &&
|
||||||
|
|
|
@ -44,10 +44,8 @@ const Template: Story< CountryInputWithCountriesProps > = ( args ) => {
|
||||||
const [ selectedCountry, selectCountry ] = useState< CountryCode | '' >(
|
const [ selectedCountry, selectCountry ] = useState< CountryCode | '' >(
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
const {
|
const { clearValidationError, showValidationError } =
|
||||||
clearValidationError,
|
useValidationContext();
|
||||||
showValidationError,
|
|
||||||
} = useValidationContext();
|
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
showValidationError( 'country' );
|
showValidationError( 'country' );
|
||||||
|
|
|
@ -46,9 +46,12 @@ const Drawer = ( {
|
||||||
overlayClassName={ classNames(
|
overlayClassName={ classNames(
|
||||||
'wc-block-components-drawer__screen-overlay',
|
'wc-block-components-drawer__screen-overlay',
|
||||||
{
|
{
|
||||||
'wc-block-components-drawer__screen-overlay--is-hidden': ! isOpen,
|
'wc-block-components-drawer__screen-overlay--is-hidden':
|
||||||
'wc-block-components-drawer__screen-overlay--with-slide-in': slideIn,
|
! isOpen,
|
||||||
'wc-block-components-drawer__screen-overlay--with-slide-out': slideOut,
|
'wc-block-components-drawer__screen-overlay--with-slide-in':
|
||||||
|
slideIn,
|
||||||
|
'wc-block-components-drawer__screen-overlay--with-slide-out':
|
||||||
|
slideOut,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
closeButtonLabel={ __(
|
closeButtonLabel={ __(
|
||||||
|
|
|
@ -6,30 +6,36 @@ import type { NumberFormatValues } from 'react-number-format';
|
||||||
/**
|
/**
|
||||||
Check if that the value is minor than the max price and greater than 0.
|
Check if that the value is minor than the max price and greater than 0.
|
||||||
*/
|
*/
|
||||||
export const isValidMaxValue = ( {
|
export const isValidMaxValue =
|
||||||
|
( {
|
||||||
maxConstraint,
|
maxConstraint,
|
||||||
minorUnit,
|
minorUnit,
|
||||||
}: {
|
}: {
|
||||||
maxConstraint: number;
|
maxConstraint: number;
|
||||||
minorUnit: number;
|
minorUnit: number;
|
||||||
} ) => ( { floatValue }: NumberFormatValues ): boolean => {
|
} ) =>
|
||||||
|
( { floatValue }: NumberFormatValues ): boolean => {
|
||||||
const maxPrice = maxConstraint / 10 ** minorUnit;
|
const maxPrice = maxConstraint / 10 ** minorUnit;
|
||||||
|
|
||||||
return floatValue !== undefined && floatValue <= maxPrice && floatValue > 0;
|
return (
|
||||||
};
|
floatValue !== undefined && floatValue <= maxPrice && floatValue > 0
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check if that the value is minor than the max price and greater than 0.
|
Check if that the value is minor than the max price and greater than 0.
|
||||||
*/
|
*/
|
||||||
export const isValidMinValue = ( {
|
export const isValidMinValue =
|
||||||
|
( {
|
||||||
minConstraint,
|
minConstraint,
|
||||||
currentMaxValue,
|
currentMaxValue,
|
||||||
minorUnit,
|
minorUnit,
|
||||||
}: {
|
}: {
|
||||||
minConstraint: number;
|
minConstraint: number;
|
||||||
currentMaxValue: number;
|
currentMaxValue: number;
|
||||||
minorUnit: number;
|
minorUnit: number;
|
||||||
} ) => ( { floatValue }: NumberFormatValues ): boolean => {
|
} ) =>
|
||||||
|
( { floatValue }: NumberFormatValues ): boolean => {
|
||||||
const minPrice = minConstraint / 10 ** minorUnit;
|
const minPrice = minConstraint / 10 ** minorUnit;
|
||||||
const currentMaxPrice = currentMaxValue / 10 ** minorUnit;
|
const currentMaxPrice = currentMaxValue / 10 ** minorUnit;
|
||||||
|
|
||||||
|
@ -38,4 +44,4 @@ export const isValidMinValue = ( {
|
||||||
floatValue >= minPrice &&
|
floatValue >= minPrice &&
|
||||||
floatValue < currentMaxPrice
|
floatValue < currentMaxPrice
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -142,9 +142,8 @@ const ProductList = ( {
|
||||||
currentPage,
|
currentPage,
|
||||||
} )
|
} )
|
||||||
);
|
);
|
||||||
const { products, totalProducts, productsLoading } = useStoreProducts(
|
const { products, totalProducts, productsLoading } =
|
||||||
queryState
|
useStoreProducts( queryState );
|
||||||
);
|
|
||||||
const { parentClassName, parentName } = useInnerBlockLayoutContext();
|
const { parentClassName, parentName } = useInnerBlockLayoutContext();
|
||||||
const totalQuery = extractPaginationAndSortAttributes( queryState );
|
const totalQuery = extractPaginationAndSortAttributes( queryState );
|
||||||
const { dispatchStoreEvent } = useStoreEvents();
|
const { dispatchStoreEvent } = useStoreEvents();
|
||||||
|
|
|
@ -37,9 +37,7 @@ export type TotalQuery = Pick< Query, 'catalog_visibility' >;
|
||||||
|
|
||||||
export type GenerateQuery = ( props: GenerateQueryProps ) => Query;
|
export type GenerateQuery = ( props: GenerateQueryProps ) => Query;
|
||||||
|
|
||||||
export type GetSortArgs = (
|
export type GetSortArgs = ( orderName: string ) =>
|
||||||
orderName: string
|
|
||||||
) =>
|
|
||||||
| {
|
| {
|
||||||
orderby: string;
|
orderby: string;
|
||||||
order: string;
|
order: string;
|
||||||
|
|
|
@ -54,7 +54,8 @@ const RadioControlAccordion = ( {
|
||||||
className={ classnames(
|
className={ classnames(
|
||||||
'wc-block-components-radio-control-accordion-content',
|
'wc-block-components-radio-control-accordion-content',
|
||||||
{
|
{
|
||||||
'wc-block-components-radio-control-accordion-content-hide': ! checked,
|
'wc-block-components-radio-control-accordion-content-hide':
|
||||||
|
! checked,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
>
|
>
|
||||||
|
|
|
@ -15,13 +15,8 @@ const Option = ( {
|
||||||
onChange,
|
onChange,
|
||||||
option,
|
option,
|
||||||
}: RadioControlOptionProps ): JSX.Element => {
|
}: RadioControlOptionProps ): JSX.Element => {
|
||||||
const {
|
const { value, label, description, secondaryLabel, secondaryDescription } =
|
||||||
value,
|
option;
|
||||||
label,
|
|
||||||
description,
|
|
||||||
secondaryLabel,
|
|
||||||
secondaryDescription,
|
|
||||||
} = option;
|
|
||||||
const onChangeValue = ( event: React.ChangeEvent< HTMLInputElement > ) =>
|
const onChangeValue = ( event: React.ChangeEvent< HTMLInputElement > ) =>
|
||||||
onChange( event.target.value );
|
onChange( event.target.value );
|
||||||
|
|
||||||
|
@ -30,7 +25,8 @@ const Option = ( {
|
||||||
className={ classnames(
|
className={ classnames(
|
||||||
'wc-block-components-radio-control__option',
|
'wc-block-components-radio-control__option',
|
||||||
{
|
{
|
||||||
'wc-block-components-radio-control__option-checked': checked,
|
'wc-block-components-radio-control__option-checked':
|
||||||
|
checked,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
htmlFor={ `${ name }-${ value }` }
|
htmlFor={ `${ name }-${ value }` }
|
||||||
|
@ -47,7 +43,8 @@ const Option = ( {
|
||||||
[ `${ name }-${ value }__label` ]: label,
|
[ `${ name }-${ value }__label` ]: label,
|
||||||
[ `${ name }-${ value }__secondary-label` ]: secondaryLabel,
|
[ `${ name }-${ value }__secondary-label` ]: secondaryLabel,
|
||||||
[ `${ name }-${ value }__description` ]: description,
|
[ `${ name }-${ value }__description` ]: description,
|
||||||
[ `${ name }-${ value }__secondary-description` ]: secondaryDescription,
|
[ `${ name }-${ value }__secondary-description` ]:
|
||||||
|
secondaryDescription,
|
||||||
} ) }
|
} ) }
|
||||||
/>
|
/>
|
||||||
<OptionLayout
|
<OptionLayout
|
||||||
|
|
|
@ -168,7 +168,8 @@ const ReviewListItem = ( { attributes, review = {} } ) => {
|
||||||
'wc-block-components-review-list-item__item',
|
'wc-block-components-review-list-item__item',
|
||||||
{
|
{
|
||||||
'is-loading': isLoading,
|
'is-loading': isLoading,
|
||||||
'wc-block-components-review-list-item__item--has-image': showReviewImage,
|
'wc-block-components-review-list-item__item--has-image':
|
||||||
|
showReviewImage,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
aria-hidden={ isLoading }
|
aria-hidden={ isLoading }
|
||||||
|
|
|
@ -4,13 +4,12 @@
|
||||||
import { actions } from './reducer';
|
import { actions } from './reducer';
|
||||||
import type { ActionType, ActionCallbackType } from './types';
|
import type { ActionType, ActionCallbackType } from './types';
|
||||||
|
|
||||||
export const emitterCallback = (
|
export const emitterCallback =
|
||||||
type: string,
|
( type: string, observerDispatch: React.Dispatch< ActionType > ) =>
|
||||||
observerDispatch: React.Dispatch< ActionType >
|
( callback: ActionCallbackType, priority = 10 ): ( () => void ) => {
|
||||||
) => ( callback: ActionCallbackType, priority = 10 ): ( () => void ) => {
|
|
||||||
const action = actions.addEventCallback( type, callback, priority );
|
const action = actions.addEventCallback( type, callback, priority );
|
||||||
observerDispatch( action );
|
observerDispatch( action );
|
||||||
return () => {
|
return () => {
|
||||||
observerDispatch( actions.removeEventCallback( type, action.id ) );
|
observerDispatch( actions.removeEventCallback( type, action.id ) );
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -95,10 +95,8 @@ describe( 'useStoreCartItemQuantity', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { setItemQuantity, quantity } =
|
||||||
const { setItemQuantity, quantity } = renderer.root.findByType(
|
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
'div'
|
|
||||||
).props;
|
|
||||||
|
|
||||||
expect( quantity ).toBe( 1 );
|
expect( quantity ).toBe( 1 );
|
||||||
|
|
||||||
|
@ -106,10 +104,8 @@ describe( 'useStoreCartItemQuantity', () => {
|
||||||
setItemQuantity( 2 );
|
setItemQuantity( 2 );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { quantity: newQuantity } =
|
||||||
const { quantity: newQuantity } = renderer.root.findByType(
|
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
'div'
|
|
||||||
).props;
|
|
||||||
|
|
||||||
expect( newQuantity ).toBe( 2 );
|
expect( newQuantity ).toBe( 2 );
|
||||||
} );
|
} );
|
||||||
|
@ -126,8 +122,7 @@ describe( 'useStoreCartItemQuantity', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { removeItem } = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
const { removeItem } = renderer.root.findByType( 'div' ).props;
|
|
||||||
|
|
||||||
act( () => {
|
act( () => {
|
||||||
removeItem();
|
removeItem();
|
||||||
|
@ -148,8 +143,7 @@ describe( 'useStoreCartItemQuantity', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { setItemQuantity } = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
const { setItemQuantity } = renderer.root.findByType( 'div' ).props;
|
|
||||||
|
|
||||||
act( () => {
|
act( () => {
|
||||||
setItemQuantity( 2 );
|
setItemQuantity( 2 );
|
||||||
|
@ -182,10 +176,8 @@ describe( 'useStoreCartItemQuantity', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { cartItemQuantityErrors } =
|
||||||
const { cartItemQuantityErrors } = renderer.root.findByType(
|
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
'div'
|
|
||||||
).props;
|
|
||||||
|
|
||||||
expect( cartItemQuantityErrors ).toEqual( mockCartErrors );
|
expect( cartItemQuantityErrors ).toEqual( mockCartErrors );
|
||||||
} );
|
} );
|
||||||
|
@ -210,8 +202,7 @@ describe( 'useStoreCartItemQuantity', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { isPendingDelete } = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
const { isPendingDelete } = renderer.root.findByType( 'div' ).props;
|
|
||||||
|
|
||||||
expect( isPendingDelete ).toBe( true );
|
expect( isPendingDelete ).toBe( true );
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -189,14 +189,10 @@ describe( 'useStoreCart', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { results, receiveCart } =
|
||||||
const { results, receiveCart } = renderer.root.findByType(
|
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
'div'
|
const { receiveCart: defaultReceiveCart, ...remaining } =
|
||||||
).props;
|
defaultCartData;
|
||||||
const {
|
|
||||||
receiveCart: defaultReceiveCart,
|
|
||||||
...remaining
|
|
||||||
} = defaultCartData;
|
|
||||||
expect( results ).toEqual( remaining );
|
expect( results ).toEqual( remaining );
|
||||||
expect( receiveCart ).toEqual( defaultReceiveCart );
|
expect( receiveCart ).toEqual( defaultReceiveCart );
|
||||||
} );
|
} );
|
||||||
|
@ -212,10 +208,8 @@ describe( 'useStoreCart', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { results, receiveCart } =
|
||||||
const { results, receiveCart } = renderer.root.findByType(
|
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
'div'
|
|
||||||
).props;
|
|
||||||
|
|
||||||
expect( results ).toEqual( mockStoreCartData );
|
expect( results ).toEqual( mockStoreCartData );
|
||||||
expect( receiveCart ).toBeUndefined();
|
expect( receiveCart ).toBeUndefined();
|
||||||
|
@ -244,10 +238,8 @@ describe( 'useStoreCart', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { results, receiveCart } =
|
||||||
const { results, receiveCart } = renderer.root.findByType(
|
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
'div'
|
|
||||||
).props;
|
|
||||||
|
|
||||||
expect( results ).toEqual( previewCartData );
|
expect( results ).toEqual( previewCartData );
|
||||||
expect( receiveCart ).toEqual( receiveCartMock );
|
expect( receiveCart ).toEqual( receiveCartMock );
|
||||||
|
|
|
@ -51,10 +51,8 @@ export const useStoreCartItemQuantity = (
|
||||||
verifiedCartItem.key = cartItem.key;
|
verifiedCartItem.key = cartItem.key;
|
||||||
verifiedCartItem.quantity = cartItem.quantity;
|
verifiedCartItem.quantity = cartItem.quantity;
|
||||||
}
|
}
|
||||||
const {
|
const { key: cartItemKey = '', quantity: cartItemQuantity = 1 } =
|
||||||
key: cartItemKey = '',
|
verifiedCartItem;
|
||||||
quantity: cartItemQuantity = 1,
|
|
||||||
} = verifiedCartItem;
|
|
||||||
const { cartErrors } = useStoreCart();
|
const { cartErrors } = useStoreCart();
|
||||||
const { dispatchActions } = useCheckoutContext();
|
const { dispatchActions } = useCheckoutContext();
|
||||||
|
|
||||||
|
@ -62,9 +60,8 @@ export const useStoreCartItemQuantity = (
|
||||||
const [ quantity, setQuantity ] = useState< number >( cartItemQuantity );
|
const [ quantity, setQuantity ] = useState< number >( cartItemQuantity );
|
||||||
const [ debouncedQuantity ] = useDebounce< number >( quantity, 400 );
|
const [ debouncedQuantity ] = useDebounce< number >( quantity, 400 );
|
||||||
const previousDebouncedQuantity = usePrevious( debouncedQuantity );
|
const previousDebouncedQuantity = usePrevious( debouncedQuantity );
|
||||||
const { removeItemFromCart, changeCartItemQuantity } = useDispatch(
|
const { removeItemFromCart, changeCartItemQuantity } =
|
||||||
storeKey
|
useDispatch( storeKey );
|
||||||
);
|
|
||||||
|
|
||||||
// Update local state when server updates.
|
// Update local state when server updates.
|
||||||
useEffect( () => setQuantity( cartItemQuantity ), [ cartItemQuantity ] );
|
useEffect( () => setQuantity( cartItemQuantity ), [ cartItemQuantity ] );
|
||||||
|
|
|
@ -179,9 +179,8 @@ export const useStoreCart = (
|
||||||
const cartData = store.getCartData();
|
const cartData = store.getCartData();
|
||||||
const cartErrors = store.getCartErrors();
|
const cartErrors = store.getCartErrors();
|
||||||
const cartTotals = store.getCartTotals();
|
const cartTotals = store.getCartTotals();
|
||||||
const cartIsLoading = ! store.hasFinishedResolution(
|
const cartIsLoading =
|
||||||
'getCartData'
|
! store.hasFinishedResolution( 'getCartData' );
|
||||||
);
|
|
||||||
|
|
||||||
const isLoadingRates = store.isCustomerDataUpdating();
|
const isLoadingRates = store.isCustomerDataUpdating();
|
||||||
const { receiveCart } = dispatch( storeKey );
|
const { receiveCart } = dispatch( storeKey );
|
||||||
|
|
|
@ -38,10 +38,8 @@ class TestErrorBoundary extends ReactComponent {
|
||||||
describe( 'useCollection', () => {
|
describe( 'useCollection', () => {
|
||||||
let registry, mocks, renderer;
|
let registry, mocks, renderer;
|
||||||
const getProps = ( testRenderer ) => {
|
const getProps = ( testRenderer ) => {
|
||||||
//eslint-disable-next-line testing-library/await-async-query
|
const { results, isLoading } =
|
||||||
const { results, isLoading } = testRenderer.root.findByType(
|
testRenderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
'div'
|
|
||||||
).props;
|
|
||||||
return {
|
return {
|
||||||
results,
|
results,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
@ -56,7 +54,9 @@ describe( 'useCollection', () => {
|
||||||
</RegistryProvider>
|
</RegistryProvider>
|
||||||
);
|
);
|
||||||
|
|
||||||
const getTestComponent = () => ( { options } ) => {
|
const getTestComponent =
|
||||||
|
() =>
|
||||||
|
( { options } ) => {
|
||||||
const items = useCollection( options );
|
const items = useCollection( options );
|
||||||
return <div { ...items } />;
|
return <div { ...items } />;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,14 +57,10 @@ export const useCollectionData = ( {
|
||||||
context = `${ context }-collection-data`;
|
context = `${ context }-collection-data`;
|
||||||
|
|
||||||
const [ collectionDataQueryState ] = useQueryStateByContext( context );
|
const [ collectionDataQueryState ] = useQueryStateByContext( context );
|
||||||
const [
|
const [ calculateAttributesQueryState, setCalculateAttributesQueryState ] =
|
||||||
calculateAttributesQueryState,
|
useQueryStateByKey( 'calculate_attribute_counts', [], context );
|
||||||
setCalculateAttributesQueryState,
|
const [ calculatePriceRangeQueryState, setCalculatePriceRangeQueryState ] =
|
||||||
] = useQueryStateByKey( 'calculate_attribute_counts', [], context );
|
useQueryStateByKey( 'calculate_price_range', null, context );
|
||||||
const [
|
|
||||||
calculatePriceRangeQueryState,
|
|
||||||
setCalculatePriceRangeQueryState,
|
|
||||||
] = useQueryStateByKey( 'calculate_price_range', null, context );
|
|
||||||
const [
|
const [
|
||||||
calculateStockStatusQueryState,
|
calculateStockStatusQueryState,
|
||||||
setCalculateStockStatusQueryState,
|
setCalculateStockStatusQueryState,
|
||||||
|
|
|
@ -64,11 +64,8 @@ export const usePaymentMethodInterface = (): PaymentMethodInterface => {
|
||||||
selectShippingRate,
|
selectShippingRate,
|
||||||
needsShipping,
|
needsShipping,
|
||||||
} = useShippingData();
|
} = useShippingData();
|
||||||
const {
|
const { billingAddress, shippingAddress, setShippingAddress } =
|
||||||
billingAddress,
|
useCustomerDataContext();
|
||||||
shippingAddress,
|
|
||||||
setShippingAddress,
|
|
||||||
} = useCustomerDataContext();
|
|
||||||
const { cartItems, cartFees, cartTotals, extensions } = useStoreCart();
|
const { cartItems, cartFees, cartTotals, extensions } = useStoreCart();
|
||||||
const { appliedCoupons } = useStoreCartCoupons();
|
const { appliedCoupons } = useStoreCartCoupons();
|
||||||
const { noticeContexts, responseTypes } = useEmitResponse();
|
const { noticeContexts, responseTypes } = useEmitResponse();
|
||||||
|
@ -98,8 +95,7 @@ export const usePaymentMethodInterface = (): PaymentMethodInterface => {
|
||||||
{
|
{
|
||||||
alternative: '',
|
alternative: '',
|
||||||
plugin: 'woocommerce-gutenberg-products-block',
|
plugin: 'woocommerce-gutenberg-products-block',
|
||||||
link:
|
link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228',
|
||||||
'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228',
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
setExpressPaymentError( errorMessage );
|
setExpressPaymentError( errorMessage );
|
||||||
|
|
|
@ -23,11 +23,11 @@ export const useSelectShippingRate = (): SelectShippingRateType => {
|
||||||
const throwError = useThrowError();
|
const throwError = useThrowError();
|
||||||
const { dispatchCheckoutEvent } = useStoreEvents();
|
const { dispatchCheckoutEvent } = useStoreEvents();
|
||||||
|
|
||||||
const { selectShippingRate: dispatchSelectShippingRate } = ( useDispatch(
|
const { selectShippingRate: dispatchSelectShippingRate } = useDispatch(
|
||||||
storeKey
|
storeKey
|
||||||
) as {
|
) as {
|
||||||
selectShippingRate: unknown;
|
selectShippingRate: unknown;
|
||||||
} ) as {
|
} as {
|
||||||
selectShippingRate: (
|
selectShippingRate: (
|
||||||
newShippingRateId: string,
|
newShippingRateId: string,
|
||||||
packageId: string | number
|
packageId: string | number
|
||||||
|
|
|
@ -43,9 +43,8 @@ export const useShippingData = (): ShippingData => {
|
||||||
// set selected rates on ref so it's always current.
|
// set selected rates on ref so it's always current.
|
||||||
const selectedRates = useRef< Record< string, unknown > >( {} );
|
const selectedRates = useRef< Record< string, unknown > >( {} );
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
const derivedSelectedRates = deriveSelectedShippingRates(
|
const derivedSelectedRates =
|
||||||
shippingRates
|
deriveSelectedShippingRates( shippingRates );
|
||||||
);
|
|
||||||
if (
|
if (
|
||||||
isObject( derivedSelectedRates ) &&
|
isObject( derivedSelectedRates ) &&
|
||||||
! isShallowEqual( selectedRates.current, derivedSelectedRates )
|
! isShallowEqual( selectedRates.current, derivedSelectedRates )
|
||||||
|
|
|
@ -18,11 +18,8 @@ jest.mock( '@woocommerce/block-data', () => ( {
|
||||||
describe( 'useStoreProducts', () => {
|
describe( 'useStoreProducts', () => {
|
||||||
let registry, mocks, renderer;
|
let registry, mocks, renderer;
|
||||||
const getProps = ( testRenderer ) => {
|
const getProps = ( testRenderer ) => {
|
||||||
const {
|
const { products, totalProducts, productsLoading } =
|
||||||
products,
|
testRenderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
||||||
totalProducts,
|
|
||||||
productsLoading,
|
|
||||||
} = testRenderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
|
|
||||||
return {
|
return {
|
||||||
products,
|
products,
|
||||||
totalProducts,
|
totalProducts,
|
||||||
|
@ -36,7 +33,9 @@ describe( 'useStoreProducts', () => {
|
||||||
</RegistryProvider>
|
</RegistryProvider>
|
||||||
);
|
);
|
||||||
|
|
||||||
const getTestComponent = () => ( { query } ) => {
|
const getTestComponent =
|
||||||
|
() =>
|
||||||
|
( { query } ) => {
|
||||||
const items = useStoreProducts( query );
|
const items = useStoreProducts( query );
|
||||||
return <div { ...items } />;
|
return <div { ...items } />;
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,10 +37,8 @@ interface CheckoutAddress {
|
||||||
*/
|
*/
|
||||||
export const useCheckoutAddress = (): CheckoutAddress => {
|
export const useCheckoutAddress = (): CheckoutAddress => {
|
||||||
const { needsShipping } = useShippingData();
|
const { needsShipping } = useShippingData();
|
||||||
const {
|
const { useShippingAsBilling, setUseShippingAsBilling } =
|
||||||
useShippingAsBilling,
|
useCheckoutContext();
|
||||||
setUseShippingAsBilling,
|
|
||||||
} = useCheckoutContext();
|
|
||||||
const {
|
const {
|
||||||
billingAddress,
|
billingAddress,
|
||||||
setBillingAddress,
|
setBillingAddress,
|
||||||
|
|
|
@ -25,10 +25,8 @@ export const useCheckoutSubmit = () => {
|
||||||
hasError,
|
hasError,
|
||||||
} = useCheckoutContext();
|
} = useCheckoutContext();
|
||||||
const { paymentMethods = {} } = usePaymentMethods();
|
const { paymentMethods = {} } = usePaymentMethods();
|
||||||
const {
|
const { activePaymentMethod, currentStatus: paymentStatus } =
|
||||||
activePaymentMethod,
|
usePaymentMethodDataContext();
|
||||||
currentStatus: paymentStatus,
|
|
||||||
} = usePaymentMethodDataContext();
|
|
||||||
const paymentMethod = paymentMethods[ activePaymentMethod ] || {};
|
const paymentMethod = paymentMethods[ activePaymentMethod ] || {};
|
||||||
const waitingForProcessing =
|
const waitingForProcessing =
|
||||||
isProcessing || isAfterProcessing || isBeforeProcessing;
|
isProcessing || isAfterProcessing || isBeforeProcessing;
|
||||||
|
|
|
@ -46,12 +46,12 @@ export const useValidation = (): ValidationData => {
|
||||||
( errorsObject: Record< string, ValidationContextError > ) =>
|
( errorsObject: Record< string, ValidationContextError > ) =>
|
||||||
setValidationErrors(
|
setValidationErrors(
|
||||||
Object.fromEntries(
|
Object.fromEntries(
|
||||||
Object.entries(
|
Object.entries( errorsObject ).map(
|
||||||
errorsObject
|
( [ validationErrorId, error ] ) => [
|
||||||
).map( ( [ validationErrorId, error ] ) => [
|
|
||||||
`${ prefix }-${ validationErrorId }`,
|
`${ prefix }-${ validationErrorId }`,
|
||||||
error,
|
error,
|
||||||
] )
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
[ setValidationErrors ]
|
[ setValidationErrors ]
|
||||||
|
|
|
@ -101,24 +101,22 @@ export const AddToCartFormStateContextProvider = ( {
|
||||||
const currentObservers = useShallowEqual( observers );
|
const currentObservers = useShallowEqual( observers );
|
||||||
const { createErrorNotice } = useDispatch( 'core/notices' );
|
const { createErrorNotice } = useDispatch( 'core/notices' );
|
||||||
const { setValidationErrors } = useValidationContext();
|
const { setValidationErrors } = useValidationContext();
|
||||||
const {
|
const { isSuccessResponse, isErrorResponse, isFailResponse } =
|
||||||
isSuccessResponse,
|
useEmitResponse();
|
||||||
isErrorResponse,
|
|
||||||
isFailResponse,
|
|
||||||
} = useEmitResponse();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {AddToCartFormEventRegistration}
|
* @type {AddToCartFormEventRegistration}
|
||||||
*/
|
*/
|
||||||
const eventRegistration = useMemo(
|
const eventRegistration = useMemo(
|
||||||
() => ( {
|
() => ( {
|
||||||
onAddToCartAfterProcessingWithSuccess: emitterObservers(
|
onAddToCartAfterProcessingWithSuccess:
|
||||||
observerDispatch
|
emitterObservers( observerDispatch )
|
||||||
).onAddToCartAfterProcessingWithSuccess,
|
.onAddToCartAfterProcessingWithSuccess,
|
||||||
onAddToCartAfterProcessingWithError: emitterObservers(
|
onAddToCartAfterProcessingWithError:
|
||||||
observerDispatch
|
emitterObservers( observerDispatch )
|
||||||
).onAddToCartAfterProcessingWithError,
|
.onAddToCartAfterProcessingWithError,
|
||||||
onAddToCartBeforeProcessing: emitterObservers( observerDispatch )
|
onAddToCartBeforeProcessing:
|
||||||
|
emitterObservers( observerDispatch )
|
||||||
.onAddToCartBeforeProcessing,
|
.onAddToCartBeforeProcessing,
|
||||||
} ),
|
} ),
|
||||||
[ observerDispatch ]
|
[ observerDispatch ]
|
||||||
|
|
|
@ -30,10 +30,8 @@ const FormSubmit = () => {
|
||||||
isProcessing,
|
isProcessing,
|
||||||
requestParams,
|
requestParams,
|
||||||
} = useAddToCartFormContext();
|
} = useAddToCartFormContext();
|
||||||
const {
|
const { hasValidationErrors, showAllValidationErrors } =
|
||||||
hasValidationErrors,
|
useValidationContext();
|
||||||
showAllValidationErrors,
|
|
||||||
} = useValidationContext();
|
|
||||||
const { createErrorNotice, removeNotice } = useDispatch( 'core/notices' );
|
const { createErrorNotice, removeNotice } = useDispatch( 'core/notices' );
|
||||||
const { receiveCart } = useStoreCart();
|
const { receiveCart } = useStoreCart();
|
||||||
const [ isSubmitting, setIsSubmitting ] = useState( false );
|
const [ isSubmitting, setIsSubmitting ] = useState( false );
|
||||||
|
@ -51,7 +49,8 @@ const FormSubmit = () => {
|
||||||
|
|
||||||
// Subscribe to emitter before processing.
|
// Subscribe to emitter before processing.
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
const unsubscribeProcessing = eventRegistration.onAddToCartBeforeProcessing(
|
const unsubscribeProcessing =
|
||||||
|
eventRegistration.onAddToCartBeforeProcessing(
|
||||||
checkValidationContext,
|
checkValidationContext,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
|
@ -81,17 +81,10 @@ export const CheckoutStateProvider = ( {
|
||||||
|
|
||||||
const { dispatchCheckoutEvent } = useStoreEvents();
|
const { dispatchCheckoutEvent } = useStoreEvents();
|
||||||
const isCalculating = checkoutState.calculatingCount > 0;
|
const isCalculating = checkoutState.calculatingCount > 0;
|
||||||
const {
|
const { isSuccessResponse, isErrorResponse, isFailResponse, shouldRetry } =
|
||||||
isSuccessResponse,
|
useEmitResponse();
|
||||||
isErrorResponse,
|
const { checkoutNotices, paymentNotices, expressPaymentNotices } =
|
||||||
isFailResponse,
|
useCheckoutNotices();
|
||||||
shouldRetry,
|
|
||||||
} = useEmitResponse();
|
|
||||||
const {
|
|
||||||
checkoutNotices,
|
|
||||||
paymentNotices,
|
|
||||||
expressPaymentNotices,
|
|
||||||
} = useCheckoutNotices();
|
|
||||||
|
|
||||||
const [ observers, observerDispatch ] = useReducer( emitReducer, {} );
|
const [ observers, observerDispatch ] = useReducer( emitReducer, {} );
|
||||||
const currentObservers = useRef( observers );
|
const currentObservers = useRef( observers );
|
||||||
|
@ -147,9 +140,8 @@ export const CheckoutStateProvider = ( {
|
||||||
setExtensionData: ( extensionData ) =>
|
setExtensionData: ( extensionData ) =>
|
||||||
void dispatch( actions.setExtensionData( extensionData ) ),
|
void dispatch( actions.setExtensionData( extensionData ) ),
|
||||||
setAfterProcessing: ( response ) => {
|
setAfterProcessing: ( response ) => {
|
||||||
const paymentResult = getPaymentResultFromCheckoutResponse(
|
const paymentResult =
|
||||||
response
|
getPaymentResultFromCheckoutResponse( response );
|
||||||
);
|
|
||||||
dispatch(
|
dispatch(
|
||||||
actions.setRedirectUrl( paymentResult?.redirectUrl || '' )
|
actions.setRedirectUrl( paymentResult?.redirectUrl || '' )
|
||||||
);
|
);
|
||||||
|
@ -244,9 +236,8 @@ export const CheckoutStateProvider = ( {
|
||||||
EMIT_TYPES.CHECKOUT_AFTER_PROCESSING_WITH_ERROR,
|
EMIT_TYPES.CHECKOUT_AFTER_PROCESSING_WITH_ERROR,
|
||||||
data
|
data
|
||||||
).then( ( observerResponses ) => {
|
).then( ( observerResponses ) => {
|
||||||
const errorResponse = handleErrorResponse(
|
const errorResponse =
|
||||||
observerResponses
|
handleErrorResponse( observerResponses );
|
||||||
);
|
|
||||||
if ( errorResponse !== null ) {
|
if ( errorResponse !== null ) {
|
||||||
// irrecoverable error so set complete
|
// irrecoverable error so set complete
|
||||||
if ( ! shouldRetry( errorResponse ) ) {
|
if ( ! shouldRetry( errorResponse ) ) {
|
||||||
|
|
|
@ -33,9 +33,8 @@ export const getPaymentResultFromCheckoutResponse = (
|
||||||
) {
|
) {
|
||||||
response.payment_result.payment_details.forEach(
|
response.payment_result.payment_details.forEach(
|
||||||
( { key, value }: { key: string; value: string } ) => {
|
( { key, value }: { key: string; value: string } ) => {
|
||||||
paymentResult.paymentDetails[ key ] = decodeEntities(
|
paymentResult.paymentDetails[ key ] =
|
||||||
value
|
decodeEntities( value );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ export enum ACTION {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note - if fields are added/shape is changed, you may want to update PRISTINE reducer clause to preserve your new field.
|
// Note - if fields are added/shape is changed, you may want to update PRISTINE reducer clause to preserve your new field.
|
||||||
export const DEFAULT_PAYMENT_DATA_CONTEXT_STATE: PaymentMethodDataContextState = {
|
export const DEFAULT_PAYMENT_DATA_CONTEXT_STATE: PaymentMethodDataContextState =
|
||||||
|
{
|
||||||
currentStatus: STATUS.PRISTINE,
|
currentStatus: STATUS.PRISTINE,
|
||||||
shouldSavePaymentMethod: false,
|
shouldSavePaymentMethod: false,
|
||||||
activePaymentMethod: '',
|
activePaymentMethod: '',
|
||||||
|
@ -34,7 +35,7 @@ export const DEFAULT_PAYMENT_DATA_CONTEXT_STATE: PaymentMethodDataContextState =
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
paymentMethods: {},
|
paymentMethods: {},
|
||||||
expressPaymentMethods: {},
|
expressPaymentMethods: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_PAYMENT_METHOD_DATA: PaymentMethodDataContextType = {
|
export const DEFAULT_PAYMENT_METHOD_DATA: PaymentMethodDataContextType = {
|
||||||
setPaymentStatus: () => ( {
|
setPaymentStatus: () => ( {
|
||||||
|
|
|
@ -70,9 +70,8 @@ export const PaymentMethodDataProvider = ( {
|
||||||
} = useCheckoutContext();
|
} = useCheckoutContext();
|
||||||
const { isEditor, getPreviewData } = useEditorContext();
|
const { isEditor, getPreviewData } = useEditorContext();
|
||||||
const { setValidationErrors } = useValidationContext();
|
const { setValidationErrors } = useValidationContext();
|
||||||
const { createErrorNotice: addErrorNotice, removeNotice } = useDispatch(
|
const { createErrorNotice: addErrorNotice, removeNotice } =
|
||||||
'core/notices'
|
useDispatch( 'core/notices' );
|
||||||
);
|
|
||||||
const {
|
const {
|
||||||
isSuccessResponse,
|
isSuccessResponse,
|
||||||
isErrorResponse,
|
isErrorResponse,
|
||||||
|
@ -93,10 +92,8 @@ export const PaymentMethodDataProvider = ( {
|
||||||
DEFAULT_PAYMENT_DATA_CONTEXT_STATE
|
DEFAULT_PAYMENT_DATA_CONTEXT_STATE
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const { dispatchActions, setPaymentStatus } =
|
||||||
dispatchActions,
|
usePaymentMethodDataDispatchers( dispatch );
|
||||||
setPaymentStatus,
|
|
||||||
} = usePaymentMethodDataDispatchers( dispatch );
|
|
||||||
|
|
||||||
const paymentMethodsInitialized = usePaymentMethods(
|
const paymentMethodsInitialized = usePaymentMethods(
|
||||||
dispatchActions.setRegisteredPaymentMethods
|
dispatchActions.setRegisteredPaymentMethods
|
||||||
|
|
|
@ -230,10 +230,8 @@ describe( 'Testing Payment Method Data Context Provider with saved cards turned
|
||||||
|
|
||||||
it( 'resets saved payment method data after starting and closing an express payment method', async () => {
|
it( 'resets saved payment method data after starting and closing an express payment method', async () => {
|
||||||
const TriggerActiveExpressPaymentMethod = () => {
|
const TriggerActiveExpressPaymentMethod = () => {
|
||||||
const {
|
const { activePaymentMethod, paymentMethodData } =
|
||||||
activePaymentMethod,
|
usePaymentMethodDataContext();
|
||||||
paymentMethodData,
|
|
||||||
} = usePaymentMethodDataContext();
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CheckoutExpressPayment />
|
<CheckoutExpressPayment />
|
||||||
|
|
|
@ -216,13 +216,14 @@ const usePaymentMethodRegistration = (
|
||||||
export const usePaymentMethods = (
|
export const usePaymentMethods = (
|
||||||
dispatcher: PaymentMethodsDispatcherType
|
dispatcher: PaymentMethodsDispatcherType
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const standardMethods: PaymentMethods = getPaymentMethods() as PaymentMethods;
|
const standardMethods: PaymentMethods =
|
||||||
|
getPaymentMethods() as PaymentMethods;
|
||||||
const { noticeContexts } = useEmitResponse();
|
const { noticeContexts } = useEmitResponse();
|
||||||
// Ensure all methods are present in order.
|
// Ensure all methods are present in order.
|
||||||
// Some payment methods may not be present in paymentGatewaySortOrder if they
|
// Some payment methods may not be present in paymentGatewaySortOrder if they
|
||||||
// depend on state, e.g. COD can depend on shipping method.
|
// depend on state, e.g. COD can depend on shipping method.
|
||||||
const displayOrder = new Set( [
|
const displayOrder = new Set( [
|
||||||
...( getSetting( 'paymentGatewaySortOrder', [] ) as [ ] ),
|
...( getSetting( 'paymentGatewaySortOrder', [] ) as [] ),
|
||||||
...Object.keys( standardMethods ),
|
...Object.keys( standardMethods ),
|
||||||
] );
|
] );
|
||||||
return usePaymentMethodRegistration(
|
return usePaymentMethodRegistration(
|
||||||
|
@ -243,7 +244,8 @@ export const usePaymentMethods = (
|
||||||
export const useExpressPaymentMethods = (
|
export const useExpressPaymentMethods = (
|
||||||
dispatcher: PaymentMethodsDispatcherType
|
dispatcher: PaymentMethodsDispatcherType
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const expressMethods: ExpressPaymentMethods = getExpressPaymentMethods() as ExpressPaymentMethods;
|
const expressMethods: ExpressPaymentMethods =
|
||||||
|
getExpressPaymentMethods() as ExpressPaymentMethods;
|
||||||
const { noticeContexts } = useEmitResponse();
|
const { noticeContexts } = useEmitResponse();
|
||||||
return usePaymentMethodRegistration(
|
return usePaymentMethodRegistration(
|
||||||
dispatcher,
|
dispatcher,
|
||||||
|
|
|
@ -61,13 +61,13 @@ export const ShippingDataProvider = ( { children } ) => {
|
||||||
const currentObservers = useRef( observers );
|
const currentObservers = useRef( observers );
|
||||||
const eventObservers = useMemo(
|
const eventObservers = useMemo(
|
||||||
() => ( {
|
() => ( {
|
||||||
onShippingRateSuccess: emitterObservers( observerDispatch )
|
onShippingRateSuccess:
|
||||||
.onSuccess,
|
emitterObservers( observerDispatch ).onSuccess,
|
||||||
onShippingRateFail: emitterObservers( observerDispatch ).onFail,
|
onShippingRateFail: emitterObservers( observerDispatch ).onFail,
|
||||||
onShippingRateSelectSuccess: emitterObservers( observerDispatch )
|
onShippingRateSelectSuccess:
|
||||||
.onSelectSuccess,
|
emitterObservers( observerDispatch ).onSelectSuccess,
|
||||||
onShippingRateSelectFail: emitterObservers( observerDispatch )
|
onShippingRateSelectFail:
|
||||||
.onSelectFail,
|
emitterObservers( observerDispatch ).onSelectFail,
|
||||||
} ),
|
} ),
|
||||||
[ observerDispatch ]
|
[ observerDispatch ]
|
||||||
);
|
);
|
||||||
|
|
|
@ -92,13 +92,8 @@ const withReviews = ( OriginalComponent ) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
getArgs( reviewsToSkip ) {
|
getArgs( reviewsToSkip ) {
|
||||||
const {
|
const { categoryIds, order, orderby, productId, reviewsToDisplay } =
|
||||||
categoryIds,
|
this.props;
|
||||||
order,
|
|
||||||
orderby,
|
|
||||||
productId,
|
|
||||||
reviewsToDisplay,
|
|
||||||
} = this.props;
|
|
||||||
const args = {
|
const args = {
|
||||||
order,
|
order,
|
||||||
orderby,
|
orderby,
|
||||||
|
@ -214,9 +209,8 @@ const withReviews = ( OriginalComponent ) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const { displayName = OriginalComponent.name || 'Component' } =
|
||||||
displayName = OriginalComponent.name || 'Component',
|
OriginalComponent;
|
||||||
} = OriginalComponent;
|
|
||||||
WrappedComponent.displayName = `WithReviews( ${ displayName } )`;
|
WrappedComponent.displayName = `WithReviews( ${ displayName } )`;
|
||||||
|
|
||||||
return WrappedComponent;
|
return WrappedComponent;
|
||||||
|
|
|
@ -11,10 +11,8 @@ import { usePositionRelativeToViewport } from '../use-position-relative-to-viewp
|
||||||
describe( 'usePositionRelativeToViewport', () => {
|
describe( 'usePositionRelativeToViewport', () => {
|
||||||
function setup() {
|
function setup() {
|
||||||
const TestComponent = () => {
|
const TestComponent = () => {
|
||||||
const [
|
const [ referenceElement, positionRelativeToViewport ] =
|
||||||
referenceElement,
|
usePositionRelativeToViewport();
|
||||||
positionRelativeToViewport,
|
|
||||||
] = usePositionRelativeToViewport();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -25,8 +25,8 @@ describe( 'usePrevious', () => {
|
||||||
renderer = TestRenderer.create( <TestComponent testValue={ 1 } /> );
|
renderer = TestRenderer.create( <TestComponent testValue={ 1 } /> );
|
||||||
} );
|
} );
|
||||||
const testValue = renderer.root.findByType( 'div' ).props.testValue;
|
const testValue = renderer.root.findByType( 'div' ).props.testValue;
|
||||||
const testPreviousValue = renderer.root.findByType( 'div' ).props
|
const testPreviousValue =
|
||||||
.previousValue;
|
renderer.root.findByType( 'div' ).props.previousValue;
|
||||||
|
|
||||||
expect( testValue ).toBe( 1 );
|
expect( testValue ).toBe( 1 );
|
||||||
expect( testPreviousValue ).toBe( undefined );
|
expect( testPreviousValue ).toBe( undefined );
|
||||||
|
@ -43,8 +43,8 @@ describe( 'usePrevious', () => {
|
||||||
renderer.update( <TestComponent testValue={ 2 } /> );
|
renderer.update( <TestComponent testValue={ 2 } /> );
|
||||||
} );
|
} );
|
||||||
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
||||||
testPreviousValue = renderer.root.findByType( 'div' ).props
|
testPreviousValue =
|
||||||
.previousValue;
|
renderer.root.findByType( 'div' ).props.previousValue;
|
||||||
expect( testValue ).toBe( 2 );
|
expect( testValue ).toBe( 2 );
|
||||||
expect( testPreviousValue ).toBe( 1 );
|
expect( testPreviousValue ).toBe( 1 );
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ describe( 'usePrevious', () => {
|
||||||
renderer.update( <TestComponent testValue={ 3 } /> );
|
renderer.update( <TestComponent testValue={ 3 } /> );
|
||||||
} );
|
} );
|
||||||
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
||||||
testPreviousValue = renderer.root.findByType( 'div' ).props
|
testPreviousValue =
|
||||||
.previousValue;
|
renderer.root.findByType( 'div' ).props.previousValue;
|
||||||
expect( testValue ).toBe( 3 );
|
expect( testValue ).toBe( 3 );
|
||||||
expect( testPreviousValue ).toBe( 2 );
|
expect( testPreviousValue ).toBe( 2 );
|
||||||
} );
|
} );
|
||||||
|
@ -73,8 +73,8 @@ describe( 'usePrevious', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
||||||
testPreviousValue = renderer.root.findByType( 'div' ).props
|
testPreviousValue =
|
||||||
.previousValue;
|
renderer.root.findByType( 'div' ).props.previousValue;
|
||||||
expect( testValue ).toBe( 'abc' );
|
expect( testValue ).toBe( 'abc' );
|
||||||
expect( testPreviousValue ).toBe( 1 );
|
expect( testPreviousValue ).toBe( 1 );
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ describe( 'usePrevious', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
testValue = renderer.root.findByType( 'div' ).props.testValue;
|
||||||
testPreviousValue = renderer.root.findByType( 'div' ).props
|
testPreviousValue =
|
||||||
.previousValue;
|
renderer.root.findByType( 'div' ).props.previousValue;
|
||||||
expect( testValue ).toBe( 3 );
|
expect( testValue ).toBe( 3 );
|
||||||
expect( testPreviousValue ).toBe( 1 );
|
expect( testPreviousValue ).toBe( 1 );
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -43,10 +43,8 @@ const style = {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export const usePositionRelativeToViewport = () => {
|
export const usePositionRelativeToViewport = () => {
|
||||||
const [
|
const [ positionRelativeToViewport, setPositionRelativeToViewport ] =
|
||||||
positionRelativeToViewport,
|
useState( '' );
|
||||||
setPositionRelativeToViewport,
|
|
||||||
] = useState( '' );
|
|
||||||
const referenceElementRef = useRef( null );
|
const referenceElementRef = useRef( null );
|
||||||
const intersectionObserver = useRef(
|
const intersectionObserver = useRef(
|
||||||
new IntersectionObserver(
|
new IntersectionObserver(
|
||||||
|
|
|
@ -16,7 +16,8 @@ import { getCanMakePayment } from './payment-method-config-helper';
|
||||||
import { assertConfigHasProperties, assertValidElement } from './assertions';
|
import { assertConfigHasProperties, assertValidElement } from './assertions';
|
||||||
|
|
||||||
export default class ExpressPaymentMethodConfig
|
export default class ExpressPaymentMethodConfig
|
||||||
implements ExpressPaymentMethodConfigInstance {
|
implements ExpressPaymentMethodConfigInstance
|
||||||
|
{
|
||||||
public name: string;
|
public name: string;
|
||||||
public content: ReactNode;
|
public content: ReactNode;
|
||||||
public edit: ReactNode;
|
public edit: ReactNode;
|
||||||
|
|
|
@ -11,12 +11,14 @@ export type NamespacedCanMakePaymentExtensionsCallbacks = Record<
|
||||||
string,
|
string,
|
||||||
CanMakePaymentExtensionCallbacks
|
CanMakePaymentExtensionCallbacks
|
||||||
>;
|
>;
|
||||||
export type ExtensionNamespace = keyof NamespacedCanMakePaymentExtensionsCallbacks;
|
export type ExtensionNamespace =
|
||||||
|
keyof NamespacedCanMakePaymentExtensionsCallbacks;
|
||||||
export type PaymentMethodName = keyof CanMakePaymentExtensionCallbacks;
|
export type PaymentMethodName = keyof CanMakePaymentExtensionCallbacks;
|
||||||
|
|
||||||
// Keeps callbacks registered by extensions for different payment methods
|
// Keeps callbacks registered by extensions for different payment methods
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
export const canMakePaymentExtensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks = {};
|
export const canMakePaymentExtensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks =
|
||||||
|
{};
|
||||||
|
|
||||||
export const extensionsConfig = {
|
export const extensionsConfig = {
|
||||||
canMakePayment: canMakePaymentExtensionsCallbacks,
|
canMakePayment: canMakePaymentExtensionsCallbacks,
|
||||||
|
|
|
@ -17,23 +17,27 @@ import {
|
||||||
} from './extensions-config';
|
} from './extensions-config';
|
||||||
|
|
||||||
// Filter out payment methods by supported features and cart requirement.
|
// Filter out payment methods by supported features and cart requirement.
|
||||||
export const canMakePaymentWithFeaturesCheck = (
|
export const canMakePaymentWithFeaturesCheck =
|
||||||
|
(
|
||||||
canMakePayment: CanMakePaymentCallback,
|
canMakePayment: CanMakePaymentCallback,
|
||||||
features: string[]
|
features: string[]
|
||||||
): CanMakePaymentCallback => ( canPayArgument ) => {
|
): CanMakePaymentCallback =>
|
||||||
|
( canPayArgument ) => {
|
||||||
const requirements = canPayArgument?.paymentRequirements || [];
|
const requirements = canPayArgument?.paymentRequirements || [];
|
||||||
const featuresSupportRequirements = requirements.every( ( requirement ) =>
|
const featuresSupportRequirements = requirements.every(
|
||||||
features.includes( requirement )
|
( requirement ) => features.includes( requirement )
|
||||||
);
|
);
|
||||||
return featuresSupportRequirements && canMakePayment( canPayArgument );
|
return featuresSupportRequirements && canMakePayment( canPayArgument );
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter out payment methods by callbacks registered by extensions.
|
// Filter out payment methods by callbacks registered by extensions.
|
||||||
export const canMakePaymentWithExtensions = (
|
export const canMakePaymentWithExtensions =
|
||||||
|
(
|
||||||
canMakePayment: CanMakePaymentCallback,
|
canMakePayment: CanMakePaymentCallback,
|
||||||
extensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks,
|
extensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks,
|
||||||
paymentMethodName: PaymentMethodName
|
paymentMethodName: PaymentMethodName
|
||||||
): CanMakePaymentCallback => ( canPayArgument ) => {
|
): CanMakePaymentCallback =>
|
||||||
|
( canPayArgument ) => {
|
||||||
// Validate whether the payment method is available based on its own criteria first.
|
// Validate whether the payment method is available based on its own criteria first.
|
||||||
let canPay = canMakePayment( canPayArgument );
|
let canPay = canMakePayment( canPayArgument );
|
||||||
|
|
||||||
|
@ -51,9 +55,12 @@ export const canMakePaymentWithExtensions = (
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
canPay = Object.keys( namespacedCallbacks ).every( ( namespace ) => {
|
canPay = Object.keys( namespacedCallbacks ).every(
|
||||||
|
( namespace ) => {
|
||||||
try {
|
try {
|
||||||
return namespacedCallbacks[ namespace ]( canPayArgument );
|
return namespacedCallbacks[ namespace ](
|
||||||
|
canPayArgument
|
||||||
|
);
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(
|
console.error(
|
||||||
|
@ -64,11 +71,12 @@ export const canMakePaymentWithExtensions = (
|
||||||
// this ensures that the error is ignored when computing the whole result.
|
// this ensures that the error is ignored when computing the whole result.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} );
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return canPay;
|
return canPay;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCanMakePayment = (
|
export const getCanMakePayment = (
|
||||||
canMakePayment: CanMakePaymentCallback,
|
canMakePayment: CanMakePaymentCallback,
|
||||||
|
@ -77,10 +85,12 @@ export const getCanMakePayment = (
|
||||||
): CanMakePaymentCallback => {
|
): CanMakePaymentCallback => {
|
||||||
const canPay = canMakePaymentWithFeaturesCheck( canMakePayment, features );
|
const canPay = canMakePaymentWithFeaturesCheck( canMakePayment, features );
|
||||||
// Loop through all callbacks to check if there are any registered for this payment method.
|
// Loop through all callbacks to check if there are any registered for this payment method.
|
||||||
return ( Object.values( extensionsConfig.canMakePayment ) as Record<
|
return (
|
||||||
|
Object.values( extensionsConfig.canMakePayment ) as Record<
|
||||||
PaymentMethodName,
|
PaymentMethodName,
|
||||||
CanMakePaymentCallback
|
CanMakePaymentCallback
|
||||||
>[] ).some( ( callbacks ) => paymentMethodName in callbacks )
|
>[]
|
||||||
|
).some( ( callbacks ) => paymentMethodName in callbacks )
|
||||||
? canMakePaymentWithExtensions(
|
? canMakePaymentWithExtensions(
|
||||||
canPay,
|
canPay,
|
||||||
extensionsConfig.canMakePayment,
|
extensionsConfig.canMakePayment,
|
||||||
|
|
|
@ -26,7 +26,8 @@ const NullComponent = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class PaymentMethodConfig
|
export default class PaymentMethodConfig
|
||||||
implements PaymentMethodConfigInstance {
|
implements PaymentMethodConfigInstance
|
||||||
|
{
|
||||||
public name: string;
|
public name: string;
|
||||||
public content: ReactNode;
|
public content: ReactNode;
|
||||||
public edit: ReactNode;
|
public edit: ReactNode;
|
||||||
|
@ -142,8 +143,7 @@ export default class PaymentMethodConfig
|
||||||
{
|
{
|
||||||
alternative: 'Pass showSavedCards and showSaveOption',
|
alternative: 'Pass showSavedCards and showSaveOption',
|
||||||
plugin: 'woocommerce-gutenberg-products-block',
|
plugin: 'woocommerce-gutenberg-products-block',
|
||||||
link:
|
link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686',
|
||||||
'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686',
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,7 @@ export const registerPaymentMethod = (
|
||||||
deprecated( 'Passing a callback to registerPaymentMethod()', {
|
deprecated( 'Passing a callback to registerPaymentMethod()', {
|
||||||
alternative: 'a config options object',
|
alternative: 'a config options object',
|
||||||
plugin: 'woocommerce-gutenberg-products-block',
|
plugin: 'woocommerce-gutenberg-products-block',
|
||||||
link:
|
link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404',
|
||||||
'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404',
|
|
||||||
} );
|
} );
|
||||||
} else {
|
} else {
|
||||||
paymentMethodConfig = new PaymentMethodConfig( options );
|
paymentMethodConfig = new PaymentMethodConfig( options );
|
||||||
|
@ -65,8 +64,7 @@ export const registerExpressPaymentMethod = (
|
||||||
deprecated( 'Passing a callback to registerExpressPaymentMethod()', {
|
deprecated( 'Passing a callback to registerExpressPaymentMethod()', {
|
||||||
alternative: 'a config options object',
|
alternative: 'a config options object',
|
||||||
plugin: 'woocommerce-gutenberg-products-block',
|
plugin: 'woocommerce-gutenberg-products-block',
|
||||||
link:
|
link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404',
|
||||||
'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404',
|
|
||||||
} );
|
} );
|
||||||
} else {
|
} else {
|
||||||
paymentMethodConfig = new ExpressPaymentMethodConfig( options );
|
paymentMethodConfig = new ExpressPaymentMethodConfig( options );
|
||||||
|
|
|
@ -153,7 +153,8 @@ describe( 'payment-method-config-helper', () => {
|
||||||
describe( 'canMakePaymentWithExtensions', () => {
|
describe( 'canMakePaymentWithExtensions', () => {
|
||||||
it( "Returns false without executing the registered callbacks, if the payment method's canMakePayment callback returns false.", () => {
|
it( "Returns false without executing the registered callbacks, if the payment method's canMakePayment callback returns false.", () => {
|
||||||
const canMakePayment = () => false;
|
const canMakePayment = () => false;
|
||||||
const canMakePaymentWithExtensionsResult = helpers.canMakePaymentWithExtensions(
|
const canMakePaymentWithExtensionsResult =
|
||||||
|
helpers.canMakePaymentWithExtensions(
|
||||||
canMakePayment,
|
canMakePayment,
|
||||||
canMakePaymentExtensionsCallbacks,
|
canMakePaymentExtensionsCallbacks,
|
||||||
'cod'
|
'cod'
|
||||||
|
|
|
@ -101,7 +101,8 @@ const ActiveAttributeFilters = ( {
|
||||||
|
|
||||||
// Remove only the slug from the URL.
|
// Remove only the slug from the URL.
|
||||||
return removeArgsFromFilterUrl( {
|
return removeArgsFromFilterUrl( {
|
||||||
[ `filter_${ attributeObject.name }` ]: slug,
|
[ `filter_${ attributeObject.name }` ]:
|
||||||
|
slug,
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
removeAttributeFilterBySlug(
|
removeAttributeFilterBySlug(
|
||||||
|
|
|
@ -125,9 +125,8 @@ const ActiveFiltersBlock = ( {
|
||||||
} );
|
} );
|
||||||
}, [ productAttributes, blockAttributes.displayStyle ] );
|
}, [ productAttributes, blockAttributes.displayStyle ] );
|
||||||
|
|
||||||
const [ productRatings, setProductRatings ] = useQueryStateByKey(
|
const [ productRatings, setProductRatings ] =
|
||||||
'ratings'
|
useQueryStateByKey( 'ratings' );
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the filter URL to set the active rating fitlers.
|
* Parse the filter URL to set the active rating fitlers.
|
||||||
|
|
|
@ -81,9 +81,8 @@ const AttributeFilterBlock = ( {
|
||||||
isString
|
isString
|
||||||
);
|
);
|
||||||
|
|
||||||
const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] = useState(
|
const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] =
|
||||||
false
|
useState( false );
|
||||||
);
|
|
||||||
|
|
||||||
const attributeObject =
|
const attributeObject =
|
||||||
blockAttributes.isPreview && ! blockAttributes.attributeId
|
blockAttributes.isPreview && ! blockAttributes.attributeId
|
||||||
|
@ -103,15 +102,11 @@ const AttributeFilterBlock = ( {
|
||||||
const borderProps = useBorderProps( blockAttributes );
|
const borderProps = useBorderProps( blockAttributes );
|
||||||
|
|
||||||
const [ queryState ] = useQueryStateByContext();
|
const [ queryState ] = useQueryStateByContext();
|
||||||
const [
|
const [ productAttributesQuery, setProductAttributesQuery ] =
|
||||||
productAttributesQuery,
|
useQueryStateByKey( 'attributes', [] );
|
||||||
setProductAttributesQuery,
|
|
||||||
] = useQueryStateByKey( 'attributes', [] );
|
|
||||||
|
|
||||||
const {
|
const { results: attributeTerms, isLoading: attributeTermsLoading } =
|
||||||
results: attributeTerms,
|
useCollection( {
|
||||||
isLoading: attributeTermsLoading,
|
|
||||||
} = useCollection( {
|
|
||||||
namespace: '/wc/store/v1',
|
namespace: '/wc/store/v1',
|
||||||
resourceName: 'products/attributes/terms',
|
resourceName: 'products/attributes/terms',
|
||||||
resourceValues: [ attributeObject?.id || 0 ],
|
resourceValues: [ attributeObject?.id || 0 ],
|
||||||
|
@ -121,10 +116,8 @@ const AttributeFilterBlock = ( {
|
||||||
const filterAvailableTerms =
|
const filterAvailableTerms =
|
||||||
blockAttributes.displayStyle !== 'dropdown' &&
|
blockAttributes.displayStyle !== 'dropdown' &&
|
||||||
blockAttributes.queryType === 'and';
|
blockAttributes.queryType === 'and';
|
||||||
const {
|
const { results: filteredCounts, isLoading: filteredCountsLoading } =
|
||||||
results: filteredCounts,
|
useCollectionData( {
|
||||||
isLoading: filteredCountsLoading,
|
|
||||||
} = useCollectionData( {
|
|
||||||
queryAttribute: {
|
queryAttribute: {
|
||||||
taxonomy: attributeObject?.taxonomy,
|
taxonomy: attributeObject?.taxonomy,
|
||||||
queryType: blockAttributes.queryType,
|
queryType: blockAttributes.queryType,
|
||||||
|
|
|
@ -98,8 +98,7 @@ const ExpressPaymentMethods = () => {
|
||||||
{
|
{
|
||||||
alternative: 'onError',
|
alternative: 'onError',
|
||||||
plugin: 'woocommerce-gutenberg-products-block',
|
plugin: 'woocommerce-gutenberg-products-block',
|
||||||
link:
|
link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228',
|
||||||
'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228',
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( errorMessage ) {
|
if ( errorMessage ) {
|
||||||
|
@ -132,7 +131,8 @@ const ExpressPaymentMethods = () => {
|
||||||
onClick: onExpressPaymentClick( id ),
|
onClick: onExpressPaymentClick( id ),
|
||||||
onClose: onExpressPaymentClose,
|
onClose: onExpressPaymentClose,
|
||||||
onError: onExpressPaymentError,
|
onError: onExpressPaymentError,
|
||||||
setExpressPaymentError: deprecatedSetExpressPaymentError,
|
setExpressPaymentError:
|
||||||
|
deprecatedSetExpressPaymentError,
|
||||||
} ) }
|
} ) }
|
||||||
</li>
|
</li>
|
||||||
) : null;
|
) : null;
|
||||||
|
|
|
@ -27,10 +27,8 @@ import PaymentMethodErrorBoundary from './payment-method-error-boundary';
|
||||||
*/
|
*/
|
||||||
const PaymentMethodCard = ( { children, showSaveOption } ) => {
|
const PaymentMethodCard = ( { children, showSaveOption } ) => {
|
||||||
const { isEditor } = useEditorContext();
|
const { isEditor } = useEditorContext();
|
||||||
const {
|
const { shouldSavePayment, setShouldSavePayment } =
|
||||||
shouldSavePayment,
|
usePaymentMethodDataContext();
|
||||||
setShouldSavePayment,
|
|
||||||
} = usePaymentMethodDataContext();
|
|
||||||
const { customerId } = useCheckoutContext();
|
const { customerId } = useCheckoutContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -34,10 +34,8 @@ const PaymentMethodOptions = () => {
|
||||||
customerPaymentMethods,
|
customerPaymentMethods,
|
||||||
} = usePaymentMethodDataContext();
|
} = usePaymentMethodDataContext();
|
||||||
const { paymentMethods } = usePaymentMethods();
|
const { paymentMethods } = usePaymentMethods();
|
||||||
const {
|
const { activePaymentMethod, ...paymentMethodInterface } =
|
||||||
activePaymentMethod,
|
usePaymentMethodInterface();
|
||||||
...paymentMethodInterface
|
|
||||||
} = usePaymentMethodInterface();
|
|
||||||
const { noticeContexts } = useEmitResponse();
|
const { noticeContexts } = useEmitResponse();
|
||||||
const { removeNotice } = useDispatch( 'core/notices' );
|
const { removeNotice } = useDispatch( 'core/notices' );
|
||||||
const { dispatchCheckoutEvent } = useStoreEvents();
|
const { dispatchCheckoutEvent } = useStoreEvents();
|
||||||
|
|
|
@ -32,7 +32,9 @@ jest.mock( '../saved-payment-method-options', () => ( { onChange } ) => {
|
||||||
|
|
||||||
jest.mock(
|
jest.mock(
|
||||||
'@woocommerce/base-components/radio-control-accordion',
|
'@woocommerce/base-components/radio-control-accordion',
|
||||||
() => ( { onChange } ) => (
|
() =>
|
||||||
|
( { onChange } ) =>
|
||||||
|
(
|
||||||
<>
|
<>
|
||||||
<span>Payment method options</span>
|
<span>Payment method options</span>
|
||||||
<button onClick={ () => onChange( 'credit-card' ) }>
|
<button onClick={ () => onChange( 'credit-card' ) }>
|
||||||
|
@ -103,10 +105,8 @@ describe( 'PaymentMethods', () => {
|
||||||
|
|
||||||
test( 'selecting new payment method', async () => {
|
test( 'selecting new payment method', async () => {
|
||||||
const ShowActivePaymentMethod = () => {
|
const ShowActivePaymentMethod = () => {
|
||||||
const {
|
const { activePaymentMethod, activeSavedToken } =
|
||||||
activePaymentMethod,
|
usePaymentMethodDataContext();
|
||||||
activeSavedToken,
|
|
||||||
} = usePaymentMethodDataContext();
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -42,16 +42,14 @@ export const useForcedLayout = ( {
|
||||||
const currentRegisteredBlocks = useRef( registeredBlocks );
|
const currentRegisteredBlocks = useRef( registeredBlocks );
|
||||||
const currentDefaultTemplate = useRef( defaultTemplate );
|
const currentDefaultTemplate = useRef( defaultTemplate );
|
||||||
|
|
||||||
const { insertBlock, replaceInnerBlocks } = useDispatch(
|
const { insertBlock, replaceInnerBlocks } =
|
||||||
'core/block-editor'
|
useDispatch( 'core/block-editor' );
|
||||||
);
|
|
||||||
|
|
||||||
const { innerBlocks, registeredBlockTypes } = useSelect(
|
const { innerBlocks, registeredBlockTypes } = useSelect(
|
||||||
( select ) => {
|
( select ) => {
|
||||||
return {
|
return {
|
||||||
innerBlocks: select( 'core/block-editor' ).getBlocks(
|
innerBlocks:
|
||||||
clientId
|
select( 'core/block-editor' ).getBlocks( clientId ),
|
||||||
),
|
|
||||||
registeredBlockTypes: currentRegisteredBlocks.current.map(
|
registeredBlockTypes: currentRegisteredBlocks.current.map(
|
||||||
( blockName ) => getBlockType( blockName )
|
( blockName ) => getBlockType( blockName )
|
||||||
),
|
),
|
||||||
|
@ -110,7 +108,8 @@ export const useForcedLayout = ( {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the forced block part of the default template, find it's original position.
|
// Is the forced block part of the default template, find it's original position.
|
||||||
const defaultTemplatePosition = currentDefaultTemplate.current.findIndex(
|
const defaultTemplatePosition =
|
||||||
|
currentDefaultTemplate.current.findIndex(
|
||||||
( [ blockName ] ) => blockName === block.name
|
( [ blockName ] ) => blockName === block.name
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,8 @@ export const useViewSwitcher = (
|
||||||
const initialView = views[ 0 ];
|
const initialView = views[ 0 ];
|
||||||
const [ currentView, setCurrentView ] = useState( initialView );
|
const [ currentView, setCurrentView ] = useState( initialView );
|
||||||
const { selectBlock } = useDispatch( 'core/block-editor' );
|
const { selectBlock } = useDispatch( 'core/block-editor' );
|
||||||
const {
|
const { getBlock, getSelectedBlockClientId, getBlockParentsByBlockName } =
|
||||||
getBlock,
|
select( blockEditorStore );
|
||||||
getSelectedBlockClientId,
|
|
||||||
getBlockParentsByBlockName,
|
|
||||||
} = select( blockEditorStore );
|
|
||||||
const selectedBlockClientId = getSelectedBlockClientId();
|
const selectedBlockClientId = getSelectedBlockClientId();
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
|
|
|
@ -114,12 +114,8 @@ const CartLineItemRow = forwardRef< HTMLTableRowElement, CartLineItemRowProps >(
|
||||||
extensions,
|
extensions,
|
||||||
} = lineItem;
|
} = lineItem;
|
||||||
|
|
||||||
const {
|
const { quantity, setItemQuantity, removeItem, isPendingDelete } =
|
||||||
quantity,
|
useStoreCartItemQuantity( lineItem );
|
||||||
setItemQuantity,
|
|
||||||
removeItem,
|
|
||||||
isPendingDelete,
|
|
||||||
} = useStoreCartItemQuantity( lineItem );
|
|
||||||
const { dispatchStoreEvent } = useStoreEvents();
|
const { dispatchStoreEvent } = useStoreEvents();
|
||||||
|
|
||||||
// Prepare props to pass to the __experimentalApplyCheckoutFilter filter.
|
// Prepare props to pass to the __experimentalApplyCheckoutFilter filter.
|
||||||
|
@ -150,9 +146,8 @@ const CartLineItemRow = forwardRef< HTMLTableRowElement, CartLineItemRowProps >(
|
||||||
amount: parseInt( prices.raw_prices.price, 10 ),
|
amount: parseInt( prices.raw_prices.price, 10 ),
|
||||||
precision: prices.raw_prices.precision,
|
precision: prices.raw_prices.precision,
|
||||||
} );
|
} );
|
||||||
const saleAmountSingle = regularAmountSingle.subtract(
|
const saleAmountSingle =
|
||||||
purchaseAmountSingle
|
regularAmountSingle.subtract( purchaseAmountSingle );
|
||||||
);
|
|
||||||
const saleAmount = saleAmountSingle.multiply( quantity );
|
const saleAmount = saleAmountSingle.multiply( quantity );
|
||||||
const totalsCurrency = getCurrencyFromPriceResponse( totals );
|
const totalsCurrency = getCurrencyFromPriceResponse( totals );
|
||||||
let lineSubtotal = parseInt( totals.line_subtotal, 10 );
|
let lineSubtotal = parseInt( totals.line_subtotal, 10 );
|
||||||
|
|
|
@ -56,7 +56,8 @@ export const Edit = ( {
|
||||||
const hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0;
|
const hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0;
|
||||||
const blockProps = useBlockProps( {
|
const blockProps = useBlockProps( {
|
||||||
className: classnames( {
|
className: classnames( {
|
||||||
'wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods': hasExpressPaymentMethods,
|
'wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods':
|
||||||
|
hasExpressPaymentMethods,
|
||||||
} ),
|
} ),
|
||||||
} );
|
} );
|
||||||
const { className } = attributes;
|
const { className } = attributes;
|
||||||
|
|
|
@ -52,7 +52,8 @@ export const Edit = ( {
|
||||||
checked={ isShippingCalculatorEnabled }
|
checked={ isShippingCalculatorEnabled }
|
||||||
onChange={ () =>
|
onChange={ () =>
|
||||||
setAttributes( {
|
setAttributes( {
|
||||||
isShippingCalculatorEnabled: ! isShippingCalculatorEnabled,
|
isShippingCalculatorEnabled:
|
||||||
|
! isShippingCalculatorEnabled,
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -56,7 +56,8 @@ export const Edit = ( {
|
||||||
checked={ showRateAfterTaxName }
|
checked={ showRateAfterTaxName }
|
||||||
onChange={ () =>
|
onChange={ () =>
|
||||||
setAttributes( {
|
setAttributes( {
|
||||||
showRateAfterTaxName: ! showRateAfterTaxName,
|
showRateAfterTaxName:
|
||||||
|
! showRateAfterTaxName,
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -36,7 +36,7 @@ const browseStoreTemplate = SHOP_URL
|
||||||
]
|
]
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const defaultTemplate = ( [
|
const defaultTemplate = [
|
||||||
[
|
[
|
||||||
'core/image',
|
'core/image',
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ const defaultTemplate = ( [
|
||||||
rows: 1,
|
rows: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
].filter( Boolean ) as unknown ) as TemplateArray;
|
].filter( Boolean ) as unknown as TemplateArray;
|
||||||
|
|
||||||
export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {
|
export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {
|
||||||
const blockProps = useBlockProps();
|
const blockProps = useBlockProps();
|
||||||
|
|
|
@ -27,10 +27,8 @@ const Block = ( {
|
||||||
} ): JSX.Element => {
|
} ): JSX.Element => {
|
||||||
const link = getSetting( 'page-' + checkoutPageId, false );
|
const link = getSetting( 'page-' + checkoutPageId, false );
|
||||||
const { isCalculating } = useCheckoutContext();
|
const { isCalculating } = useCheckoutContext();
|
||||||
const [
|
const [ positionReferenceElement, positionRelativeToViewport ] =
|
||||||
positionReferenceElement,
|
usePositionRelativeToViewport();
|
||||||
positionRelativeToViewport,
|
|
||||||
] = usePositionRelativeToViewport();
|
|
||||||
const [ showSpinner, setShowSpinner ] = useState( false );
|
const [ showSpinner, setShowSpinner ] = useState( false );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
|
|
|
@ -16,7 +16,8 @@ __webpack_public_path__ = WC_BLOCKS_BUILD_URL;
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.FILLED_CART,
|
metadata: metadata.FILLED_CART,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/filled-cart" */
|
/* webpackChunkName: "cart-blocks/filled-cart" */
|
||||||
'./filled-cart-block/frontend'
|
'./filled-cart-block/frontend'
|
||||||
|
@ -26,7 +27,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.EMPTY_CART,
|
metadata: metadata.EMPTY_CART,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/empty-cart" */
|
/* webpackChunkName: "cart-blocks/empty-cart" */
|
||||||
'./empty-cart-block/frontend'
|
'./empty-cart-block/frontend'
|
||||||
|
@ -36,7 +38,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ITEMS,
|
metadata: metadata.CART_ITEMS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/cart-items" */
|
/* webpackChunkName: "cart-blocks/cart-items" */
|
||||||
'./cart-items-block/frontend'
|
'./cart-items-block/frontend'
|
||||||
|
@ -46,7 +49,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_LINE_ITEMS,
|
metadata: metadata.CART_LINE_ITEMS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/cart-line-items" */
|
/* webpackChunkName: "cart-blocks/cart-line-items" */
|
||||||
'./cart-line-items-block/frontend'
|
'./cart-line-items-block/frontend'
|
||||||
|
@ -56,7 +60,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_TOTALS,
|
metadata: metadata.CART_TOTALS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/cart-totals" */
|
/* webpackChunkName: "cart-blocks/cart-totals" */
|
||||||
'./cart-totals-block/frontend'
|
'./cart-totals-block/frontend'
|
||||||
|
@ -66,7 +71,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_EXPRESS_PAYMENT,
|
metadata: metadata.CART_EXPRESS_PAYMENT,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/cart-express-payment" */
|
/* webpackChunkName: "cart-blocks/cart-express-payment" */
|
||||||
'./cart-express-payment-block/frontend'
|
'./cart-express-payment-block/frontend'
|
||||||
|
@ -76,7 +82,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.PROCEED_TO_CHECKOUT,
|
metadata: metadata.PROCEED_TO_CHECKOUT,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/proceed-to-checkout" */
|
/* webpackChunkName: "cart-blocks/proceed-to-checkout" */
|
||||||
'./proceed-to-checkout-block/frontend'
|
'./proceed-to-checkout-block/frontend'
|
||||||
|
@ -86,7 +93,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ACCEPTED_PAYMENT_METHODS,
|
metadata: metadata.CART_ACCEPTED_PAYMENT_METHODS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/cart-accepted-payment-methods" */
|
/* webpackChunkName: "cart-blocks/cart-accepted-payment-methods" */
|
||||||
'./cart-accepted-payment-methods-block/frontend'
|
'./cart-accepted-payment-methods-block/frontend'
|
||||||
|
@ -96,7 +104,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY,
|
metadata: metadata.CART_ORDER_SUMMARY,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/cart-order-summary" */
|
/* webpackChunkName: "cart-blocks/cart-order-summary" */
|
||||||
'./cart-order-summary-block/frontend'
|
'./cart-order-summary-block/frontend'
|
||||||
|
@ -106,7 +115,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_HEADING,
|
metadata: metadata.CART_ORDER_SUMMARY_HEADING,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-heading" */
|
/* webpackChunkName: "cart-blocks/order-summary-heading" */
|
||||||
'./cart-order-summary-heading/frontend'
|
'./cart-order-summary-heading/frontend'
|
||||||
|
@ -116,7 +126,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_SUBTOTAL,
|
metadata: metadata.CART_ORDER_SUMMARY_SUBTOTAL,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-subtotal" */
|
/* webpackChunkName: "cart-blocks/order-summary-subtotal" */
|
||||||
'./cart-order-summary-subtotal/frontend'
|
'./cart-order-summary-subtotal/frontend'
|
||||||
|
@ -126,7 +137,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_FEE,
|
metadata: metadata.CART_ORDER_SUMMARY_FEE,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-fee" */
|
/* webpackChunkName: "cart-blocks/order-summary-fee" */
|
||||||
'./cart-order-summary-fee/frontend'
|
'./cart-order-summary-fee/frontend'
|
||||||
|
@ -136,7 +148,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_DISCOUNT,
|
metadata: metadata.CART_ORDER_SUMMARY_DISCOUNT,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-discount" */
|
/* webpackChunkName: "cart-blocks/order-summary-discount" */
|
||||||
'./cart-order-summary-discount/frontend'
|
'./cart-order-summary-discount/frontend'
|
||||||
|
@ -146,7 +159,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_COUPON_FORM,
|
metadata: metadata.CART_ORDER_SUMMARY_COUPON_FORM,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-coupon-form" */
|
/* webpackChunkName: "cart-blocks/order-summary-coupon-form" */
|
||||||
'./cart-order-summary-coupon-form/frontend'
|
'./cart-order-summary-coupon-form/frontend'
|
||||||
|
@ -156,7 +170,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_SHIPPING,
|
metadata: metadata.CART_ORDER_SUMMARY_SHIPPING,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-shipping" */
|
/* webpackChunkName: "cart-blocks/order-summary-shipping" */
|
||||||
'./cart-order-summary-shipping/frontend'
|
'./cart-order-summary-shipping/frontend'
|
||||||
|
@ -166,7 +181,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_TAXES,
|
metadata: metadata.CART_ORDER_SUMMARY_TAXES,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-taxes" */
|
/* webpackChunkName: "cart-blocks/order-summary-taxes" */
|
||||||
'./cart-order-summary-taxes/frontend'
|
'./cart-order-summary-taxes/frontend'
|
||||||
|
@ -176,7 +192,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CART_ORDER_SUMMARY_HEADING,
|
metadata: metadata.CART_ORDER_SUMMARY_HEADING,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "cart-blocks/order-summary-heading" */
|
/* webpackChunkName: "cart-blocks/order-summary-heading" */
|
||||||
'./cart-order-summary-heading/frontend'
|
'./cart-order-summary-heading/frontend'
|
||||||
|
|
|
@ -104,14 +104,10 @@ const ScrollOnError = ( {
|
||||||
}: {
|
}: {
|
||||||
scrollToTop: ( props: Record< string, unknown > ) => void;
|
scrollToTop: ( props: Record< string, unknown > ) => void;
|
||||||
} ): null => {
|
} ): null => {
|
||||||
const {
|
const { hasError: checkoutHasError, isIdle: checkoutIsIdle } =
|
||||||
hasError: checkoutHasError,
|
useCheckoutContext();
|
||||||
isIdle: checkoutIsIdle,
|
const { hasValidationErrors, showAllValidationErrors } =
|
||||||
} = useCheckoutContext();
|
useValidationContext();
|
||||||
const {
|
|
||||||
hasValidationErrors,
|
|
||||||
showAllValidationErrors,
|
|
||||||
} = useValidationContext();
|
|
||||||
|
|
||||||
const hasErrorsToDisplay =
|
const hasErrorsToDisplay =
|
||||||
checkoutIsIdle &&
|
checkoutIsIdle &&
|
||||||
|
|
|
@ -41,17 +41,17 @@ export const CheckoutBlockContext = createContext< CheckoutBlockContextProps >(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const CheckoutBlockControlsContext = createContext<
|
export const CheckoutBlockControlsContext =
|
||||||
CheckoutBlockControlsContextProps
|
createContext< CheckoutBlockControlsContextProps >( {
|
||||||
>( {
|
|
||||||
addressFieldControls: () => null,
|
addressFieldControls: () => null,
|
||||||
accountControls: () => null,
|
accountControls: () => null,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
export const useCheckoutBlockContext = (): CheckoutBlockContextProps => {
|
export const useCheckoutBlockContext = (): CheckoutBlockContextProps => {
|
||||||
return useContext( CheckoutBlockContext );
|
return useContext( CheckoutBlockContext );
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useCheckoutBlockControlsContext = (): CheckoutBlockControlsContextProps => {
|
export const useCheckoutBlockControlsContext =
|
||||||
|
(): CheckoutBlockControlsContextProps => {
|
||||||
return useContext( CheckoutBlockControlsContext );
|
return useContext( CheckoutBlockControlsContext );
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,7 +34,8 @@ export const FormStepBlock = ( {
|
||||||
const { title = '', description = '', showStepNumber = true } = attributes;
|
const { title = '', description = '', showStepNumber = true } = attributes;
|
||||||
const blockProps = useBlockProps( {
|
const blockProps = useBlockProps( {
|
||||||
className: classnames( 'wc-block-components-checkout-step', className, {
|
className: classnames( 'wc-block-components-checkout-step', className, {
|
||||||
'wc-block-components-checkout-step--with-step-number': showStepNumber,
|
'wc-block-components-checkout-step--with-step-number':
|
||||||
|
showStepNumber,
|
||||||
} ),
|
} ),
|
||||||
} );
|
} );
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -39,9 +39,8 @@ export const Edit = ( {
|
||||||
showPhoneField,
|
showPhoneField,
|
||||||
requirePhoneField,
|
requirePhoneField,
|
||||||
} = useCheckoutBlockContext();
|
} = useCheckoutBlockContext();
|
||||||
const {
|
const { addressFieldControls: Controls } =
|
||||||
addressFieldControls: Controls,
|
useCheckoutBlockControlsContext();
|
||||||
} = useCheckoutBlockControlsContext();
|
|
||||||
const { showBillingFields } = useCheckoutAddress();
|
const { showBillingFields } = useCheckoutAddress();
|
||||||
|
|
||||||
if ( ! showBillingFields ) {
|
if ( ! showBillingFields ) {
|
||||||
|
|
|
@ -20,11 +20,8 @@ const Block = ( {
|
||||||
}: {
|
}: {
|
||||||
allowCreateAccount: boolean;
|
allowCreateAccount: boolean;
|
||||||
} ): JSX.Element => {
|
} ): JSX.Element => {
|
||||||
const {
|
const { customerId, shouldCreateAccount, setShouldCreateAccount } =
|
||||||
customerId,
|
useCheckoutContext();
|
||||||
shouldCreateAccount,
|
|
||||||
setShouldCreateAccount,
|
|
||||||
} = useCheckoutContext();
|
|
||||||
const { billingAddress, setEmail } = useCheckoutAddress();
|
const { billingAddress, setEmail } = useCheckoutAddress();
|
||||||
const { dispatchCheckoutEvent } = useStoreEvents();
|
const { dispatchCheckoutEvent } = useStoreEvents();
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,8 @@ export const Edit = ( {
|
||||||
const blockProps = useBlockProps( {
|
const blockProps = useBlockProps( {
|
||||||
className: classnames(
|
className: classnames(
|
||||||
{
|
{
|
||||||
'wp-block-woocommerce-checkout-express-payment-block--has-express-payment-methods': hasExpressPaymentMethods,
|
'wp-block-woocommerce-checkout-express-payment-block--has-express-payment-methods':
|
||||||
|
hasExpressPaymentMethods,
|
||||||
},
|
},
|
||||||
attributes?.className
|
attributes?.className
|
||||||
),
|
),
|
||||||
|
|
|
@ -34,11 +34,10 @@ export const Edit = ( {
|
||||||
} );
|
} );
|
||||||
const allowedBlocks = getAllowedBlocks( innerBlockAreas.CHECKOUT_FIELDS );
|
const allowedBlocks = getAllowedBlocks( innerBlockAreas.CHECKOUT_FIELDS );
|
||||||
|
|
||||||
const {
|
const { addressFieldControls: Controls } =
|
||||||
addressFieldControls: Controls,
|
useCheckoutBlockControlsContext();
|
||||||
} = useCheckoutBlockControlsContext();
|
|
||||||
|
|
||||||
const defaultTemplate = ( [
|
const defaultTemplate = [
|
||||||
[ 'woocommerce/checkout-express-payment-block', {}, [] ],
|
[ 'woocommerce/checkout-express-payment-block', {}, [] ],
|
||||||
[ 'woocommerce/checkout-contact-information-block', {}, [] ],
|
[ 'woocommerce/checkout-contact-information-block', {}, [] ],
|
||||||
[ 'woocommerce/checkout-shipping-address-block', {}, [] ],
|
[ 'woocommerce/checkout-shipping-address-block', {}, [] ],
|
||||||
|
@ -48,7 +47,7 @@ export const Edit = ( {
|
||||||
[ 'woocommerce/checkout-order-note-block', {}, [] ],
|
[ 'woocommerce/checkout-order-note-block', {}, [] ],
|
||||||
[ 'woocommerce/checkout-terms-block', {}, [] ],
|
[ 'woocommerce/checkout-terms-block', {}, [] ],
|
||||||
[ 'woocommerce/checkout-actions-block', {}, [] ],
|
[ 'woocommerce/checkout-actions-block', {}, [] ],
|
||||||
].filter( Boolean ) as unknown ) as TemplateArray;
|
].filter( Boolean ) as unknown as TemplateArray;
|
||||||
|
|
||||||
useForcedLayout( {
|
useForcedLayout( {
|
||||||
clientId,
|
clientId,
|
||||||
|
|
|
@ -103,8 +103,7 @@ jest.mock( '@woocommerce/base-context/hooks', () => ( {
|
||||||
meta_data: [
|
meta_data: [
|
||||||
{
|
{
|
||||||
key: 'Items',
|
key: 'Items',
|
||||||
value:
|
value: 'Hoodie - Blue, Yes × 1, Beanie × 1',
|
||||||
'Hoodie - Blue, Yes × 1, Beanie × 1',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
selected: false,
|
selected: false,
|
||||||
|
@ -128,8 +127,7 @@ jest.mock( '@woocommerce/base-context/hooks', () => ( {
|
||||||
meta_data: [
|
meta_data: [
|
||||||
{
|
{
|
||||||
key: 'Items',
|
key: 'Items',
|
||||||
value:
|
value: 'Hoodie - Blue, Yes × 1, Beanie × 1',
|
||||||
'Hoodie - Blue, Yes × 1, Beanie × 1',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
selected: false,
|
selected: false,
|
||||||
|
@ -153,8 +151,7 @@ jest.mock( '@woocommerce/base-context/hooks', () => ( {
|
||||||
meta_data: [
|
meta_data: [
|
||||||
{
|
{
|
||||||
key: 'Items',
|
key: 'Items',
|
||||||
value:
|
value: 'Hoodie - Blue, Yes × 1, Beanie × 1',
|
||||||
'Hoodie - Blue, Yes × 1, Beanie × 1',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
selected: true,
|
selected: true,
|
||||||
|
@ -476,8 +473,7 @@ describe( 'Checkout Order Summary', () => {
|
||||||
meta_data: [
|
meta_data: [
|
||||||
{
|
{
|
||||||
key: 'Items',
|
key: 'Items',
|
||||||
value:
|
value: 'Hoodie - Blue, Yes × 1, Beanie × 1',
|
||||||
'Hoodie - Blue, Yes × 1, Beanie × 1',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
selected: true,
|
selected: true,
|
||||||
|
|
|
@ -13,9 +13,8 @@ const Block = ( {
|
||||||
} ): JSX.Element | null => {
|
} ): JSX.Element | null => {
|
||||||
const couponsEnabled = getSetting( 'couponsEnabled', true );
|
const couponsEnabled = getSetting( 'couponsEnabled', true );
|
||||||
|
|
||||||
const { applyCoupon, isApplyingCoupon } = useStoreCartCoupons(
|
const { applyCoupon, isApplyingCoupon } =
|
||||||
'wc/checkout'
|
useStoreCartCoupons( 'wc/checkout' );
|
||||||
);
|
|
||||||
|
|
||||||
if ( ! couponsEnabled ) {
|
if ( ! couponsEnabled ) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -27,9 +27,8 @@ const DiscountSlotFill = (): JSX.Element => {
|
||||||
|
|
||||||
const Block = ( { className = '' }: { className?: string } ): JSX.Element => {
|
const Block = ( { className = '' }: { className?: string } ): JSX.Element => {
|
||||||
const { cartTotals, cartCoupons } = useStoreCart();
|
const { cartTotals, cartCoupons } = useStoreCart();
|
||||||
const { removeCoupon, isRemovingCoupon } = useStoreCartCoupons(
|
const { removeCoupon, isRemovingCoupon } =
|
||||||
'wc/checkout'
|
useStoreCartCoupons( 'wc/checkout' );
|
||||||
);
|
|
||||||
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );
|
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -56,7 +56,8 @@ export const Edit = ( {
|
||||||
checked={ showRateAfterTaxName }
|
checked={ showRateAfterTaxName }
|
||||||
onChange={ () =>
|
onChange={ () =>
|
||||||
setAttributes( {
|
setAttributes( {
|
||||||
showRateAfterTaxName: ! showRateAfterTaxName,
|
showRateAfterTaxName:
|
||||||
|
! showRateAfterTaxName,
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -38,9 +38,8 @@ export const Edit = ( {
|
||||||
showPhoneField,
|
showPhoneField,
|
||||||
requirePhoneField,
|
requirePhoneField,
|
||||||
} = useCheckoutBlockContext();
|
} = useCheckoutBlockContext();
|
||||||
const {
|
const { addressFieldControls: Controls } =
|
||||||
addressFieldControls: Controls,
|
useCheckoutBlockControlsContext();
|
||||||
} = useCheckoutBlockControlsContext();
|
|
||||||
return (
|
return (
|
||||||
<FormStepBlock
|
<FormStepBlock
|
||||||
setAttributes={ setAttributes }
|
setAttributes={ setAttributes }
|
||||||
|
|
|
@ -60,9 +60,8 @@ const Block = (): JSX.Element | null => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shippingRatesPackageCount = getShippingRatesPackageCount(
|
const shippingRatesPackageCount =
|
||||||
shippingRates
|
getShippingRatesPackageCount( shippingRates );
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
! isEditor &&
|
! isEditor &&
|
||||||
|
|
|
@ -32,11 +32,8 @@ const FrontendBlock = ( {
|
||||||
const { isDisabled } = useCheckoutSubmit();
|
const { isDisabled } = useCheckoutSubmit();
|
||||||
|
|
||||||
const validationErrorId = 'terms-and-conditions-' + instanceId;
|
const validationErrorId = 'terms-and-conditions-' + instanceId;
|
||||||
const {
|
const { getValidationError, setValidationErrors, clearValidationError } =
|
||||||
getValidationError,
|
validation;
|
||||||
setValidationErrors,
|
|
||||||
clearValidationError,
|
|
||||||
} = validation;
|
|
||||||
|
|
||||||
const error = getValidationError( validationErrorId ) || {};
|
const error = getValidationError( validationErrorId ) || {};
|
||||||
const hasError = error.message && ! error.hidden;
|
const hasError = error.message && ! error.hidden;
|
||||||
|
|
|
@ -91,8 +91,7 @@ describe( 'Edit', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<Edit
|
<Edit
|
||||||
attributes={ {
|
attributes={ {
|
||||||
text:
|
text: 'I agree to the <a href="/terms">terms</a> and <a href="/privacy">privacy</a>',
|
||||||
'I agree to the <a href="/terms">terms</a> and <a href="/privacy">privacy</a>',
|
|
||||||
checkbox: true,
|
checkbox: true,
|
||||||
} }
|
} }
|
||||||
setAttributes={ () => void 0 }
|
setAttributes={ () => void 0 }
|
||||||
|
|
|
@ -17,7 +17,8 @@ __webpack_public_path__ = WC_BLOCKS_BUILD_URL;
|
||||||
// @todo When forcing all blocks at once, they will append based on the order they are registered. Introduce formal sorting param.
|
// @todo When forcing all blocks at once, they will append based on the order they are registered. Introduce formal sorting param.
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_FIELDS,
|
metadata: metadata.CHECKOUT_FIELDS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/fields" */ './checkout-fields-block/frontend'
|
/* webpackChunkName: "checkout-blocks/fields" */ './checkout-fields-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -26,7 +27,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_EXPRESS_PAYMENT,
|
metadata: metadata.CHECKOUT_EXPRESS_PAYMENT,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/express-payment" */ './checkout-express-payment-block/block'
|
/* webpackChunkName: "checkout-blocks/express-payment" */ './checkout-express-payment-block/block'
|
||||||
)
|
)
|
||||||
|
@ -35,7 +37,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_CONTACT_INFORMATION,
|
metadata: metadata.CHECKOUT_CONTACT_INFORMATION,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/contact-information" */ './checkout-contact-information-block/frontend'
|
/* webpackChunkName: "checkout-blocks/contact-information" */ './checkout-contact-information-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -44,7 +47,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_SHIPPING_ADDRESS,
|
metadata: metadata.CHECKOUT_SHIPPING_ADDRESS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/shipping-address" */ './checkout-shipping-address-block/frontend'
|
/* webpackChunkName: "checkout-blocks/shipping-address" */ './checkout-shipping-address-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -53,7 +57,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_BILLING_ADDRESS,
|
metadata: metadata.CHECKOUT_BILLING_ADDRESS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/billing-address" */ './checkout-billing-address-block/frontend'
|
/* webpackChunkName: "checkout-blocks/billing-address" */ './checkout-billing-address-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -62,7 +67,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_SHIPPING_METHODS,
|
metadata: metadata.CHECKOUT_SHIPPING_METHODS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/shipping-methods" */ './checkout-shipping-methods-block/frontend'
|
/* webpackChunkName: "checkout-blocks/shipping-methods" */ './checkout-shipping-methods-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -71,7 +77,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_PAYMENT,
|
metadata: metadata.CHECKOUT_PAYMENT,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/payment" */ './checkout-payment-block/frontend'
|
/* webpackChunkName: "checkout-blocks/payment" */ './checkout-payment-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -80,7 +87,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_NOTE,
|
metadata: metadata.CHECKOUT_ORDER_NOTE,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-note" */ './checkout-order-note-block/block'
|
/* webpackChunkName: "checkout-blocks/order-note" */ './checkout-order-note-block/block'
|
||||||
)
|
)
|
||||||
|
@ -89,7 +97,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_TERMS,
|
metadata: metadata.CHECKOUT_TERMS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/terms" */ './checkout-terms-block/frontend'
|
/* webpackChunkName: "checkout-blocks/terms" */ './checkout-terms-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -98,7 +107,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ACTIONS,
|
metadata: metadata.CHECKOUT_ACTIONS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/actions" */ './checkout-actions-block/frontend'
|
/* webpackChunkName: "checkout-blocks/actions" */ './checkout-actions-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -107,7 +117,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_TOTALS,
|
metadata: metadata.CHECKOUT_TOTALS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/totals" */ './checkout-totals-block/frontend'
|
/* webpackChunkName: "checkout-blocks/totals" */ './checkout-totals-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -116,7 +127,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary" */ './checkout-order-summary-block/frontend'
|
/* webpackChunkName: "checkout-blocks/order-summary" */ './checkout-order-summary-block/frontend'
|
||||||
)
|
)
|
||||||
|
@ -125,7 +137,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY_CART_ITEMS,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY_CART_ITEMS,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary-cart-items" */
|
/* webpackChunkName: "checkout-blocks/order-summary-cart-items" */
|
||||||
'./checkout-order-summary-cart-items/frontend'
|
'./checkout-order-summary-cart-items/frontend'
|
||||||
|
@ -135,7 +148,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY_SUBTOTAL,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY_SUBTOTAL,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary-subtotal" */
|
/* webpackChunkName: "checkout-blocks/order-summary-subtotal" */
|
||||||
'./checkout-order-summary-subtotal/frontend'
|
'./checkout-order-summary-subtotal/frontend'
|
||||||
|
@ -145,7 +159,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY_FEE,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY_FEE,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary-fee" */
|
/* webpackChunkName: "checkout-blocks/order-summary-fee" */
|
||||||
'./checkout-order-summary-fee/frontend'
|
'./checkout-order-summary-fee/frontend'
|
||||||
|
@ -155,7 +170,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY_DISCOUNT,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY_DISCOUNT,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary-discount" */
|
/* webpackChunkName: "checkout-blocks/order-summary-discount" */
|
||||||
'./checkout-order-summary-discount/frontend'
|
'./checkout-order-summary-discount/frontend'
|
||||||
|
@ -165,7 +181,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY_COUPON_FORM,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY_COUPON_FORM,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary-coupon-form" */
|
/* webpackChunkName: "checkout-blocks/order-summary-coupon-form" */
|
||||||
'./checkout-order-summary-coupon-form/frontend'
|
'./checkout-order-summary-coupon-form/frontend'
|
||||||
|
@ -175,7 +192,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY_SHIPPING,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY_SHIPPING,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary-shipping" */
|
/* webpackChunkName: "checkout-blocks/order-summary-shipping" */
|
||||||
'./checkout-order-summary-shipping/frontend'
|
'./checkout-order-summary-shipping/frontend'
|
||||||
|
@ -185,7 +203,8 @@ registerCheckoutBlock( {
|
||||||
|
|
||||||
registerCheckoutBlock( {
|
registerCheckoutBlock( {
|
||||||
metadata: metadata.CHECKOUT_ORDER_SUMMARY_TAXES,
|
metadata: metadata.CHECKOUT_ORDER_SUMMARY_TAXES,
|
||||||
component: lazy( () =>
|
component: lazy(
|
||||||
|
() =>
|
||||||
import(
|
import(
|
||||||
/* webpackChunkName: "checkout-blocks/order-summary-taxes" */
|
/* webpackChunkName: "checkout-blocks/order-summary-taxes" */
|
||||||
'./checkout-order-summary-taxes/frontend'
|
'./checkout-order-summary-taxes/frontend'
|
||||||
|
|
|
@ -136,12 +136,10 @@ export const BlockControls = ( {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const withBlockControls = ( {
|
export const withBlockControls =
|
||||||
cropLabel,
|
( { cropLabel, editLabel }: BlockControlsConfiguration ) =>
|
||||||
editLabel,
|
< T extends EditorBlock< T > >( Component: ComponentType< T > ) =>
|
||||||
}: BlockControlsConfiguration ) => < T extends EditorBlock< T > >(
|
( props: WithBlockControlsProps< T > ) => {
|
||||||
Component: ComponentType< T >
|
|
||||||
) => ( props: WithBlockControlsProps< T > ) => {
|
|
||||||
const [ isEditingImage, setIsEditingImage ] = props.useEditingImage;
|
const [ isEditingImage, setIsEditingImage ] = props.useEditingImage;
|
||||||
const { attributes, category, name, product, setAttributes } = props;
|
const { attributes, category, name, product, setAttributes } = props;
|
||||||
const { contentAlign, editMode, mediaId, mediaSrc } = attributes;
|
const { contentAlign, editMode, mediaId, mediaSrc } = attributes;
|
||||||
|
@ -171,4 +169,4 @@ export const withBlockControls = ( {
|
||||||
<Component { ...props } />
|
<Component { ...props } />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -92,15 +92,17 @@ export const ImageEditor = ( {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const withImageEditor = < T extends EditorBlock< T > >(
|
export const withImageEditor =
|
||||||
Component: ComponentType< T >
|
< T extends EditorBlock< T > >( Component: ComponentType< T > ) =>
|
||||||
) => ( props: WithImageEditorProps< T > ) => {
|
( props: WithImageEditorProps< T > ) => {
|
||||||
const [ isEditingImage, setIsEditingImage ] = props.useEditingImage;
|
const [ isEditingImage, setIsEditingImage ] = props.useEditingImage;
|
||||||
|
|
||||||
const { attributes, backgroundImageSize, name, setAttributes } = props;
|
const { attributes, backgroundImageSize, name, setAttributes } = props;
|
||||||
const { mediaId, mediaSrc } = attributes;
|
const { mediaId, mediaSrc } = attributes;
|
||||||
const item =
|
const item =
|
||||||
name === BLOCK_NAMES.featuredProduct ? props.product : props.category;
|
name === BLOCK_NAMES.featuredProduct
|
||||||
|
? props.product
|
||||||
|
: props.category;
|
||||||
|
|
||||||
const { backgroundImageId, backgroundImageSrc } = useBackgroundImage( {
|
const { backgroundImageId, backgroundImageSrc } = useBackgroundImage( {
|
||||||
item,
|
item,
|
||||||
|
@ -123,4 +125,4 @@ export const withImageEditor = < T extends EditorBlock< T > >(
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Component { ...props } />;
|
return <Component { ...props } />;
|
||||||
};
|
};
|
||||||
|
|
|
@ -287,9 +287,9 @@ export const InspectorControls = ( {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const withInspectorControls = < T extends EditorBlock< T > >(
|
export const withInspectorControls =
|
||||||
Component: ComponentType< T >
|
< T extends EditorBlock< T > >( Component: ComponentType< T > ) =>
|
||||||
) => ( props: WithInspectorControlsProps< T > ) => {
|
( props: WithInspectorControlsProps< T > ) => {
|
||||||
const { attributes, name, setAttributes } = props;
|
const { attributes, name, setAttributes } = props;
|
||||||
const {
|
const {
|
||||||
alt,
|
alt,
|
||||||
|
@ -307,7 +307,9 @@ export const withInspectorControls = < T extends EditorBlock< T > >(
|
||||||
} = attributes;
|
} = attributes;
|
||||||
|
|
||||||
const item =
|
const item =
|
||||||
name === BLOCK_NAMES.featuredProduct ? props.product : props.category;
|
name === BLOCK_NAMES.featuredProduct
|
||||||
|
? props.product
|
||||||
|
: props.category;
|
||||||
|
|
||||||
const { setGradient } = useGradient( {
|
const { setGradient } = useGradient( {
|
||||||
gradientAttribute: 'overlayGradient',
|
gradientAttribute: 'overlayGradient',
|
||||||
|
@ -353,4 +355,4 @@ export const withInspectorControls = < T extends EditorBlock< T > >(
|
||||||
<Component { ...props } />
|
<Component { ...props } />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,9 +61,8 @@ export function getBackgroundImageStyles( {
|
||||||
...( url && {
|
...( url && {
|
||||||
backgroundImage: `url(${ url })`,
|
backgroundImage: `url(${ url })`,
|
||||||
} ),
|
} ),
|
||||||
backgroundPosition: calculatePercentPositionFromCoordinates(
|
backgroundPosition:
|
||||||
focalPoint
|
calculatePercentPositionFromCoordinates( focalPoint ),
|
||||||
),
|
|
||||||
...( ! isRepeated && {
|
...( ! isRepeated && {
|
||||||
backgroundRepeat: 'no-repeat',
|
backgroundRepeat: 'no-repeat',
|
||||||
backgroundSize: imageFit === 'cover' ? imageFit : 'auto',
|
backgroundSize: imageFit === 'cover' ? imageFit : 'auto',
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue