2021-09-21 12:38:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useBlockProps } from '@wordpress/block-editor';
|
|
|
|
import { useExpressPaymentMethods } from '@woocommerce/base-context/hooks';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block';
|
|
|
|
import './editor.scss';
|
|
|
|
|
2021-10-25 15:31:22 +00:00
|
|
|
export const Edit = ( {
|
|
|
|
attributes,
|
|
|
|
}: {
|
|
|
|
attributes: { className: string };
|
|
|
|
} ): JSX.Element | null => {
|
2021-09-21 12:38:56 +00:00
|
|
|
const { paymentMethods, isInitialized } = useExpressPaymentMethods();
|
|
|
|
const hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0;
|
2021-09-24 13:44:05 +00:00
|
|
|
const blockProps = useBlockProps( {
|
2021-09-21 12:38:56 +00:00
|
|
|
className: classnames( {
|
2022-06-15 09:56:52 +00:00
|
|
|
'wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods':
|
|
|
|
hasExpressPaymentMethods,
|
2021-09-21 12:38:56 +00:00
|
|
|
} ),
|
|
|
|
} );
|
2021-10-25 15:31:22 +00:00
|
|
|
const { className } = attributes;
|
2021-09-21 12:38:56 +00:00
|
|
|
|
2023-04-06 11:16:42 +00:00
|
|
|
if ( ! isInitialized || ! hasExpressPaymentMethods ) {
|
2021-09-21 12:38:56 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div { ...blockProps }>
|
2023-04-06 11:16:42 +00:00
|
|
|
<Block className={ className } />
|
2021-09-21 12:38:56 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return <div { ...useBlockProps.save() } />;
|
|
|
|
};
|