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

Commit c873eec

Browse files
authored
Introduce pluginArea in Cart and Checkout (#3498)
* add plugin area * add invisible errorBoundary * move PluginArea to CheckoutProvider
1 parent d532547 commit c873eec

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

assets/js/base/components/block-error-boundary/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ class BlockErrorBoundary extends Component {
3939
showErrorMessage,
4040
text,
4141
errorMessagePrefix,
42+
renderError,
4243
} = this.props;
4344
const { errorMessage, hasError } = this.state;
4445

4546
if ( hasError ) {
47+
if ( typeof renderError === 'function' ) {
48+
return renderError( { errorMessage } );
49+
}
4650
return (
4751
<BlockError
4852
errorMessage={ showErrorMessage ? errorMessage : null }
@@ -85,6 +89,10 @@ BlockErrorBoundary.propTypes = {
8589
* Text preceeding the error message.
8690
*/
8791
errorMessagePrefix: PropTypes.string,
92+
/**
93+
* Render function to show a custom error component.
94+
*/
95+
renderError: PropTypes.func,
8896
};
8997

9098
BlockErrorBoundary.defaultProps = {

assets/js/base/context/cart-checkout/checkout/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { PluginArea } from '@wordpress/plugins';
5+
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/block-settings';
6+
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
7+
18
/**
29
* Internal dependencies
310
*/
@@ -31,6 +38,15 @@ export const CheckoutProvider = ( {
3138
<ShippingDataProvider>
3239
<PaymentMethodDataProvider>
3340
{ children }
41+
{ /* If the current user is an admin, we let BlockErrorBoundary render
42+
the error, or we simply die silently. */ }
43+
<BlockErrorBoundary
44+
renderError={
45+
CURRENT_USER_IS_ADMIN ? null : () => null
46+
}
47+
>
48+
<PluginArea />
49+
</BlockErrorBoundary>
3450
<CheckoutProcessor />
3551
</PaymentMethodDataProvider>
3652
</ShippingDataProvider>

package-lock.json

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
"@wordpress/autop": "2.9.0",
154154
"@wordpress/deprecated": "2.9.0",
155155
"@wordpress/notices": "2.9.1",
156+
"@wordpress/plugins": "^2.23.0",
156157
"@wordpress/wordcount": "2.11.0",
157158
"classnames": "2.2.6",
158159
"compare-versions": "3.6.0",

0 commit comments

Comments
 (0)