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

Commit 6339f97

Browse files
remove proptypes from payment-method-card and payment-method-error-bo… (#9817)
* proptype removal * updated payment-method-error-boundary.tsx --------- Co-authored-by: Niels Lange <[email protected]>
1 parent cc55ca7 commit 6339f97

File tree

3 files changed

+60
-75
lines changed

3 files changed

+60
-75
lines changed

assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-card.js renamed to assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-card.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { __ } from '@wordpress/i18n';
55
import { useEditorContext } from '@woocommerce/base-context';
66
import { CheckboxControl } from '@woocommerce/blocks-checkout';
7-
import PropTypes from 'prop-types';
87
import { useSelect, useDispatch } from '@wordpress/data';
98
import { CHECKOUT_STORE_KEY, PAYMENT_STORE_KEY } from '@woocommerce/block-data';
109

@@ -23,7 +22,14 @@ import PaymentMethodErrorBoundary from './payment-method-error-boundary';
2322
*
2423
* @return {*} The rendered component.
2524
*/
26-
const PaymentMethodCard = ( { children, showSaveOption } ) => {
25+
interface PaymentMethodCardProps {
26+
showSaveOption: boolean;
27+
children: React.ReactNode;
28+
}
29+
const PaymentMethodCard = ( {
30+
children,
31+
showSaveOption,
32+
}: PaymentMethodCardProps ) => {
2733
const { isEditor } = useEditorContext();
2834
const { shouldSavePaymentMethod, customerId } = useSelect( ( select ) => {
2935
const paymentMethodStore = select( PAYMENT_STORE_KEY );
@@ -58,9 +64,4 @@ const PaymentMethodCard = ( { children, showSaveOption } ) => {
5864
);
5965
};
6066

61-
PaymentMethodCard.propTypes = {
62-
showSaveOption: PropTypes.bool,
63-
children: PropTypes.node,
64-
};
65-
6667
export default PaymentMethodCard;

assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-error-boundary.js

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { __ } from '@wordpress/i18n';
5+
import { useState } from '@wordpress/element';
6+
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
7+
import { StoreNoticesContainer } from '@woocommerce/blocks-checkout';
8+
import { noticeContexts } from '@woocommerce/base-context';
9+
import { NoticeType } from '@woocommerce/types';
10+
interface PaymentMethodErrorBoundaryProps {
11+
isEditor: boolean;
12+
children: React.ReactNode;
13+
}
14+
const PaymentMethodErrorBoundary = ( {
15+
isEditor,
16+
children,
17+
}: PaymentMethodErrorBoundaryProps ) => {
18+
const [ errorMessage ] = useState( '' );
19+
const [ hasError ] = useState( false );
20+
if ( hasError ) {
21+
let errorText = __(
22+
'We are experiencing difficulties with this payment method. Please contact us for assistance.',
23+
'woo-gutenberg-products-block'
24+
);
25+
if ( isEditor || CURRENT_USER_IS_ADMIN ) {
26+
if ( errorMessage ) {
27+
errorText = errorMessage;
28+
} else {
29+
errorText = __(
30+
"There was an error with this payment method. Please verify it's configured correctly.",
31+
'woo-gutenberg-products-block'
32+
);
33+
}
34+
}
35+
const notices: NoticeType[] = [
36+
{
37+
id: '0',
38+
content: errorText,
39+
isDismissible: false,
40+
status: 'error',
41+
},
42+
];
43+
return (
44+
<StoreNoticesContainer
45+
additionalNotices={ notices }
46+
context={ noticeContexts.PAYMENTS }
47+
/>
48+
);
49+
}
50+
return <>{ children }</>;
51+
};
52+
export default PaymentMethodErrorBoundary;

0 commit comments

Comments
 (0)