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';
|
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 }>
|
2022-11-24 14:20:44 +00:00
|
|
|
<ShippingDataProvider>
|
|
|
|
<PaymentEventsProvider>
|
|
|
|
{ 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. */ }
|
2022-11-24 14:20:44 +00:00
|
|
|
<BlockErrorBoundary
|
|
|
|
renderError={
|
|
|
|
CURRENT_USER_IS_ADMIN ? null : () => null
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<PluginArea scope="woocommerce-checkout" />
|
|
|
|
</BlockErrorBoundary>
|
|
|
|
<CheckoutProcessor />
|
|
|
|
</PaymentEventsProvider>
|
|
|
|
</ShippingDataProvider>
|
2022-06-21 14:09:22 +00:00
|
|
|
</CheckoutEventsProvider>
|
2020-03-10 13:39:21 +00:00
|
|
|
);
|
|
|
|
};
|