2020-12-04 09:52:52 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { PluginArea } from '@wordpress/plugins';
|
|
|
|
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/block-settings';
|
|
|
|
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
|
2021-01-11 12:12:26 +00:00
|
|
|
import { SlotFillProvider } from '@woocommerce/blocks-checkout';
|
2020-12-04 09:52:52 +00:00
|
|
|
|
2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { PaymentMethodDataProvider } from '../payment-methods';
|
2020-03-26 13:31:09 +00:00
|
|
|
import { ShippingDataProvider } from '../shipping';
|
2020-11-20 15:13:35 +00:00
|
|
|
import { CustomerDataProvider } from '../customer';
|
2020-04-01 09:27:53 +00:00
|
|
|
import { CheckoutStateProvider } from '../checkout-state';
|
|
|
|
import CheckoutProcessor from './processor';
|
2020-03-10 13:39:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkout provider
|
|
|
|
* This wraps the checkout and provides an api interface for the checkout to
|
|
|
|
* children via various hooks.
|
|
|
|
*
|
2020-04-30 09:52:36 +00:00
|
|
|
* @param {Object} props Incoming props for the provider.
|
|
|
|
* @param {Object} props.children The children being wrapped.
|
2020-11-16 13:12:56 +00:00
|
|
|
* @param {boolean} [props.isCart] Whether it's rendered in the Cart
|
|
|
|
* component.
|
2020-04-30 09:52:36 +00:00
|
|
|
* @param {string} [props.redirectUrl] Initialize what the checkout will
|
|
|
|
* redirect to after successful
|
|
|
|
* submit.
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
2020-11-16 13:12:56 +00:00
|
|
|
export const CheckoutProvider = ( {
|
|
|
|
children,
|
|
|
|
isCart = false,
|
|
|
|
redirectUrl,
|
|
|
|
} ) => {
|
2020-03-10 13:39:21 +00:00
|
|
|
return (
|
2020-11-16 13:12:56 +00:00
|
|
|
<CheckoutStateProvider redirectUrl={ redirectUrl } isCart={ isCart }>
|
2020-11-20 15:13:35 +00:00
|
|
|
<CustomerDataProvider>
|
2020-04-08 16:36:04 +00:00
|
|
|
<ShippingDataProvider>
|
2020-04-15 00:05:01 +00:00
|
|
|
<PaymentMethodDataProvider>
|
2021-01-11 12:12:26 +00:00
|
|
|
<SlotFillProvider>
|
|
|
|
{ children }
|
|
|
|
{ /* If the current user is an admin, we let BlockErrorBoundary render
|
2021-01-07 12:02:21 +00:00
|
|
|
the error, or we simply die silently. */ }
|
2021-01-11 12:12:26 +00:00
|
|
|
<BlockErrorBoundary
|
|
|
|
renderError={
|
|
|
|
CURRENT_USER_IS_ADMIN ? null : () => null
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<PluginArea />
|
|
|
|
</BlockErrorBoundary>
|
|
|
|
</SlotFillProvider>
|
2020-03-26 13:31:09 +00:00
|
|
|
<CheckoutProcessor />
|
2020-04-08 16:36:04 +00:00
|
|
|
</PaymentMethodDataProvider>
|
|
|
|
</ShippingDataProvider>
|
2020-11-20 15:13:35 +00:00
|
|
|
</CustomerDataProvider>
|
2020-04-01 09:27:53 +00:00
|
|
|
</CheckoutStateProvider>
|
2020-03-10 13:39:21 +00:00
|
|
|
);
|
|
|
|
};
|