2019-12-03 14:12:46 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { withRestApiHydration } from '@woocommerce/block-hocs';
|
2020-03-05 19:54:05 +00:00
|
|
|
import { useStoreCart } from '@woocommerce/base-hooks';
|
2019-12-03 14:12:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block.js';
|
2020-03-05 13:06:47 +00:00
|
|
|
import blockAttributes from './attributes';
|
2019-12-03 14:12:46 +00:00
|
|
|
import renderFrontend from '../../../utils/render-frontend.js';
|
|
|
|
|
2020-03-05 19:54:05 +00:00
|
|
|
/**
|
|
|
|
* Wrapper component to supply API data.
|
|
|
|
*
|
|
|
|
* @param {Object} attributes object of key value attributes passed to block.
|
|
|
|
*/
|
|
|
|
const CheckoutFrontend = ( attributes ) => {
|
|
|
|
const { shippingRates } = useStoreCart();
|
|
|
|
return <Block attributes={ attributes } shippingRates={ shippingRates } />;
|
|
|
|
};
|
|
|
|
|
2020-03-04 15:13:38 +00:00
|
|
|
const getProps = ( el ) => {
|
2020-03-05 13:06:47 +00:00
|
|
|
const attributes = {};
|
|
|
|
|
|
|
|
Object.keys( blockAttributes ).forEach( ( key ) => {
|
|
|
|
if ( typeof el.dataset[ key ] !== 'undefined' ) {
|
|
|
|
if (
|
|
|
|
el.dataset[ key ] === 'true' ||
|
|
|
|
el.dataset[ key ] === 'false'
|
|
|
|
) {
|
|
|
|
attributes[ key ] = el.dataset[ key ] !== 'false';
|
|
|
|
} else {
|
|
|
|
attributes[ key ] = el.dataset[ key ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2019-12-03 14:12:46 +00:00
|
|
|
return {
|
2020-03-05 13:06:47 +00:00
|
|
|
attributes,
|
2019-12-03 14:12:46 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
renderFrontend(
|
|
|
|
'.wp-block-woocommerce-checkout',
|
2020-03-05 19:54:05 +00:00
|
|
|
withRestApiHydration( CheckoutFrontend ),
|
2019-12-03 14:12:46 +00:00
|
|
|
getProps
|
|
|
|
);
|