Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Add conversion template (#10077)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Sep 19, 2023
1 parent 87c33a8 commit 62f0b75
Showing 1 changed file with 86 additions and 3 deletions.
89 changes: 86 additions & 3 deletions assets/js/blocks/classic-template/order-confirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,88 @@
/**
* External dependencies
*/

import { createBlock, type BlockInstance } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import type { OnClickCallbackParameter, InheritedAttributes } from './types';

const isConversionPossible = () => {
return false;
return true;
};

const getButtonLabel = () =>
__( 'Transform into blocks', 'woo-gutenberg-products-block' );

const getBlockifiedTemplate = ( inheritedAttributes: InheritedAttributes ) =>
[
createBlock(
'woocommerce/order-confirmation-status',
inheritedAttributes
),
createBlock(
'woocommerce/order-confirmation-summary',
inheritedAttributes
),
createBlock(
'woocommerce/order-confirmation-details',
inheritedAttributes
),
createBlock( 'core/columns', inheritedAttributes, [
createBlock( 'core/column', inheritedAttributes, [
createBlock( 'core/heading', {
level: 3,
content: __(
'Billing Address',
'woo-gutenberg-products-block'
),
} ),
createBlock(
'woocommerce/order-confirmation-billing-address',
inheritedAttributes
),
] ),
createBlock( 'core/column', inheritedAttributes, [
createBlock( 'core/heading', {
level: 3,
content: __(
'Shipping Address',
'woo-gutenberg-products-block'
),
} ),
createBlock(
'woocommerce/order-confirmation-shipping-address',
inheritedAttributes
),
] ),
] ),
].filter( Boolean ) as BlockInstance[];

const onClickCallback = ( {
clientId,
attributes,
getBlocks,
replaceBlock,
selectBlock,
}: OnClickCallbackParameter ) => {
replaceBlock( clientId, getBlockifiedTemplate( attributes ) );

const blocks = getBlocks();

const groupBlock = blocks.find(
( block ) =>
block.name === 'core/group' &&
block.innerBlocks.some(
( innerBlock ) =>
innerBlock.name === 'woocommerce/store-notices'
)
);

if ( groupBlock ) {
selectBlock( groupBlock.clientId );
}
};

const getDescription = () => {
Expand Down Expand Up @@ -150,4 +227,10 @@ const getSkeleton = () => {
);
};

export { isConversionPossible, getDescription, getSkeleton };
const blockifyConfig = {
getButtonLabel,
onClickCallback,
getBlockifiedTemplate,
};

export { blockifyConfig, isConversionPossible, getDescription, getSkeleton };

0 comments on commit 62f0b75

Please sign in to comment.