2021-07-22 11:03:00 +00:00
/ * *
* External dependencies
* /
2021-08-20 11:30:38 +00:00
import { __ } from '@wordpress/i18n' ;
2021-07-22 11:03:00 +00:00
import { useBlockProps } from '@wordpress/block-editor' ;
2021-08-20 11:30:38 +00:00
import { Placeholder , Button } from 'wordpress-components' ;
import { useExpressPaymentMethods } from '@woocommerce/base-context/hooks' ;
2022-02-01 16:54:38 +00:00
import { Icon , payment } from '@wordpress/icons' ;
2021-08-20 11:30:38 +00:00
import { ADMIN_URL } from '@woocommerce/settings' ;
import classnames from 'classnames' ;
2021-07-22 11:03:00 +00:00
/ * *
* Internal dependencies
* /
import Block from './block' ;
import './editor.scss' ;
2021-08-20 11:30:38 +00:00
/ * *
* Renders a placeholder in the editor .
* /
const NoExpressPaymentMethodsPlaceholder = ( ) = > {
return (
< Placeholder
2022-02-01 16:54:38 +00:00
icon = { < Icon icon = { payment } / > }
2021-08-20 11:30:38 +00:00
label = { __ ( 'Express Checkout' , 'woo-gutenberg-products-block' ) }
className = "wp-block-woocommerce-checkout-express-payment-block-placeholder"
>
< span className = "wp-block-woocommerce-checkout-express-payment-block-placeholder__description" >
{ __ (
2022-09-12 08:39:26 +00:00
'Your store does not have any payment methods that support the Express Checkout block. Once you have configured a compatible payment method, it will be displayed here.' ,
2021-08-20 11:30:38 +00:00
'woo-gutenberg-products-block'
) }
< / span >
< Button
isPrimary
href = { ` ${ ADMIN_URL } admin.php?page=wc-settings&tab=checkout ` }
target = "_blank"
rel = "noopener noreferrer"
className = "wp-block-woocommerce-checkout-express-payment-block-placeholder__button"
>
{ __ (
'Configure Payment Methods' ,
'woo-gutenberg-products-block'
) }
< / Button >
< / Placeholder >
) ;
} ;
2021-08-16 10:20:27 +00:00
export const Edit = ( {
attributes ,
} : {
attributes : {
2021-10-20 16:18:13 +00:00
className? : string ;
2021-08-16 10:20:27 +00:00
lock : {
move : boolean ;
remove : boolean ;
} ;
} ;
2021-08-20 11:30:38 +00:00
} ) : JSX . Element | null = > {
const { paymentMethods , isInitialized } = useExpressPaymentMethods ( ) ;
const hasExpressPaymentMethods = Object . keys ( paymentMethods ) . length > 0 ;
2021-09-24 13:44:05 +00:00
const blockProps = useBlockProps ( {
2021-10-20 16:18:13 +00:00
className : classnames (
{
2022-06-15 09:56:52 +00:00
'wp-block-woocommerce-checkout-express-payment-block--has-express-payment-methods' :
hasExpressPaymentMethods ,
2021-10-20 16:18:13 +00:00
} ,
attributes ? . className
) ,
2021-08-20 11:30:38 +00:00
attributes ,
} ) ;
if ( ! isInitialized ) {
return null ;
}
2021-07-22 11:03:00 +00:00
return (
< div { ...blockProps } >
2021-08-20 11:30:38 +00:00
{ hasExpressPaymentMethods ? (
< Block / >
) : (
< NoExpressPaymentMethodsPlaceholder / >
) }
2021-07-22 11:03:00 +00:00
< / div >
) ;
} ;
export const Save = ( ) : JSX . Element = > {
return < div { ...useBlockProps.save ( ) } / > ;
} ;