2020-12-04 09:52:52 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { PluginArea } from '@wordpress/plugins';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
|
2020-12-04 09:52:52 +00:00
|
|
|
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
|
2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-10-06 12:46:46 +00:00
|
|
|
import { PaymentEventsProvider } from './payment-events';
|
2021-08-30 14:35:20 +00:00
|
|
|
import { ShippingDataProvider } from './shipping';
|
|
|
|
import { CustomerDataProvider } from './customer';
|
2022-06-21 14:09:22 +00:00
|
|
|
import { CheckoutEventsProvider } from './checkout-events';
|
2021-08-30 14:35:20 +00:00
|
|
|
import CheckoutProcessor from './checkout-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.
|
|
|
|
*
|
2022-06-10 16:33:15 +00:00
|
|
|
* @param {Object} props Incoming props for the provider.
|
|
|
|
* @param {Object} props.children The children being wrapped.
|
|
|
|
* component.
|
|
|
|
* @param {string} [props.redirectUrl] Initialize what the checkout will
|
|
|
|
* redirect to after successful
|
|
|
|
* submit.
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const CheckoutProvider = ( { children, redirectUrl } ) => {
|
2020-03-10 13:39:21 +00:00
|
|
|
return (
|
2022-06-21 14:09:22 +00:00
|
|
|
<CheckoutEventsProvider redirectUrl={ redirectUrl }>
|
2020-11-20 15:13:35 +00:00
|
|
|
<CustomerDataProvider>
|
2020-04-08 16:36:04 +00:00
|
|
|
<ShippingDataProvider>
|
2022-10-06 12:46:46 +00:00
|
|
|
<PaymentEventsProvider>
|
2021-07-08 15:04:13 +00:00
|
|
|
{ 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-07-08 15:04:13 +00:00
|
|
|
<BlockErrorBoundary
|
|
|
|
renderError={
|
|
|
|
CURRENT_USER_IS_ADMIN ? null : () => null
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<PluginArea scope="woocommerce-checkout" />
|
|
|
|
</BlockErrorBoundary>
|
2020-03-26 13:31:09 +00:00
|
|
|
<CheckoutProcessor />
|
2022-10-06 12:46:46 +00:00
|
|
|
</PaymentEventsProvider>
|
2020-04-08 16:36:04 +00:00
|
|
|
</ShippingDataProvider>
|
2020-11-20 15:13:35 +00:00
|
|
|
</CustomerDataProvider>
|
2022-06-21 14:09:22 +00:00
|
|
|
</CheckoutEventsProvider>
|
2020-03-10 13:39:21 +00:00
|
|
|
);
|
|
|
|
};
|