Skip to content

Commit

Permalink
Server register inner coupon block
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Aug 11, 2022
1 parent 8fbc2cd commit 1c18a86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import Title from '@woocommerce/base-components/title';
import classnames from 'classnames';
import { useState } from '@wordpress/element';

const Block = ( {
className,
Expand All @@ -11,12 +12,16 @@ const Block = ( {
className: string;
content: string;
} ): JSX.Element => {
const [ count, setCount ] = useState( 0 );
return (
<Title
headingLevel="2"
className={ classnames( className, 'wc-block-cart__totals-title' ) }
>
{ content }
<button
onClick={ () => setCount( count + 1 ) }
>{ `Counter: ${ count }` }</button>
</Title>
);
};
Expand Down
16 changes: 12 additions & 4 deletions src/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ public function block_hydration_wrapper( $block_content, $block, $instance ) {
return $block_content;
}

$block_type = $instance->block_type;
$attr_definitions = isset( $block_type ) ? $block_type->attributes : [];
$block_type = $instance->block_type;
if ( ! $block_type ) {
// We might use a better way to flag it here.
wc_add_notice( 'You need to make a server registration of ' . $block['blockName'], 'error' );
}
$attr_definitions = $block_type->attributes;

$attributes = array();
$sourced_attributes = array();
Expand Down Expand Up @@ -193,8 +197,8 @@ public function block_hydration_wrapper( $block_content, $block, $instance ) {
'data-wp-block-props="%6$s" ' .
'data-wp-block-hydration="idle">',
esc_attr( $block['blockName'] ),
esc_attr( wp_json_encode( isset( $block_type ) ? $block_type->uses_context : [] ) ),
esc_attr( wp_json_encode( isset( $block_type ) ? $block_type->provides_context : [] ) ),
esc_attr( wp_json_encode( $block_type->uses_context ) ),
esc_attr( wp_json_encode( $block_type->provides_context ) ),
esc_attr( wp_json_encode( $attributes ) ),
esc_attr( wp_json_encode( $sourced_attributes ) ),
esc_attr( wp_json_encode( $block_supports_attributes ) )
Expand Down Expand Up @@ -287,6 +291,10 @@ protected function get_block_types() {
];

$block_types = array_merge( $block_types, Cart::get_cart_block_types(), Checkout::get_checkout_block_types() );
if ( Package::feature()->is_feature_plugin_build() ) {
$block_types[] = 'Checkout';
$block_types[] = 'Cart';
}

if ( Package::feature()->is_experimental_build() ) {
$block_types[] = 'SingleProduct';
Expand Down

0 comments on commit 1c18a86

Please sign in to comment.