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

Commit

Permalink
Order confirmation: Convert Order Details Templates to Blocks (#10095)
Browse files Browse the repository at this point in the history
* Move code from templates into the details block

* Details -> Totals

* Downloads block

* Sample content for downloads block

* Add block icon
  • Loading branch information
mikejolley authored and tarhi-saad committed Aug 25, 2023
1 parent daebed2 commit 3d117e1
Show file tree
Hide file tree
Showing 13 changed files with 547 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "woocommerce/order-confirmation-details",
"name": "woocommerce/order-confirmation-downloads",
"version": "1.0.0",
"title": "Order Confirmation Details",
"description": "Display the order confirmation details.",
"title": "Order Downloads",
"description": "Display links to purchased downloads.",
"category": "woocommerce",
"keywords": [ "WooCommerce" ],
"supports": {
Expand Down
43 changes: 43 additions & 0 deletions assets/js/blocks/order-confirmation/downloads/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* External dependencies
*/
import ServerSideRender from '@wordpress/server-side-render';
import { useBlockProps } from '@wordpress/block-editor';
import { Disabled } from '@wordpress/components';

/**
* Internal dependencies
*/
import './style.scss';

interface Props {
attributes: {
align: string;
className: string;
isPreview: boolean;
};
name: string;
}

const Edit = ( props: Props ): JSX.Element => {
const { attributes, name } = props;
const blockProps = useBlockProps( {
className: 'wc-block-order-confirmation-downloads',
} );

return (
<div { ...blockProps }>
<Disabled>
<ServerSideRender
block={ name }
attributes={ {
...attributes,
isPreview: true,
} }
/>
</Disabled>
</div>
);
};

export default Edit;
30 changes: 30 additions & 0 deletions assets/js/blocks/order-confirmation/downloads/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* External dependencies
*/
import { registerBlockType } from '@wordpress/blocks';
import { Icon, download } from '@wordpress/icons';

/**
* Internal dependencies
*/
import metadata from './block.json';
import edit from './edit';
import './style.scss';

registerBlockType( metadata, {
icon: {
src: (
<Icon
icon={ download }
className="wc-block-editor-components-block-icon"
/>
),
},
attributes: {
...metadata.attributes,
},
edit,
save() {
return null;
},
} );
27 changes: 27 additions & 0 deletions assets/js/blocks/order-confirmation/downloads/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.wc-block-order-confirmation-downloads {
.woocommerce-order-downloads table,
.woocommerce-order-downloads table.shop_table {
width: 100%;
border: 1px solid currentColor;
border-bottom: 0;

thead {
text-transform: uppercase;
}

th {
font-weight: bold;
}

th,
td {
border-style: solid;
border-color: currentColor;
border-width: 0 0 1px 0;
padding: $gap-small;
margin: 0;
text-align: left;
}
}
}

29 changes: 29 additions & 0 deletions assets/js/blocks/order-confirmation/totals/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "woocommerce/order-confirmation-totals",
"version": "1.0.0",
"title": "Order Totals",
"description": "Display the items purchased and order totals.",
"category": "woocommerce",
"keywords": [ "WooCommerce" ],
"supports": {
"multiple": false,
"align": [ "wide", "full" ]
},
"attributes": {
"align": {
"type": "string",
"default": "wide"
},
"className": {
"type": "string",
"default": ""
},
"isPreview": {
"type": "boolean",
"default": false
}
},
"textdomain": "woo-gutenberg-products-block",
"apiVersion": 2,
"$schema": "https://schemas.wp.org/trunk/block.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ import { useBlockProps } from '@wordpress/block-editor';
*/
import './style.scss';

interface Props {
attributes: {
align: string;
className: string;
isPreview: boolean;
};
name: string;
}

const Edit = ( props: Props ): JSX.Element => {
const { attributes, name } = props;
const blockProps = useBlockProps( {
className: 'wc-block-order-confirmation-details',
className: 'wc-block-order-confirmation-totals',
} );

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wc-block-order-confirmation-details {
.wc-block-order-confirmation-totals {
.woocommerce-order-details table,
.woocommerce-order-details table.shop_table {
width: 100%;
Expand All @@ -9,6 +9,10 @@
text-transform: uppercase;
}

th {
font-weight: bold;
}

th,
td {
border-style: solid;
Expand Down
7 changes: 5 additions & 2 deletions bin/webpack-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ const blocks = {
'order-confirmation-summary': {
customDir: 'order-confirmation/summary',
},
'order-confirmation-details': {
customDir: 'order-confirmation/details',
'order-confirmation-totals': {
customDir: 'order-confirmation/totals',
},
'order-confirmation-downloads': {
customDir: 'order-confirmation/downloads',
},
'order-confirmation-billing-address': {
customDir: 'order-confirmation/billing-address',
Expand Down
158 changes: 0 additions & 158 deletions src/BlockTypes/OrderConfirmation/Details.php

This file was deleted.

Loading

0 comments on commit 3d117e1

Please sign in to comment.