2020-05-27 14:45:18 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { withProduct } from '@woocommerce/block-hocs';
|
2020-06-05 12:18:16 +00:00
|
|
|
import {
|
|
|
|
InnerBlockLayoutContextProvider,
|
|
|
|
ProductDataContextProvider,
|
|
|
|
} from '@woocommerce/shared-context';
|
2020-07-30 10:57:22 +00:00
|
|
|
import { StoreNoticesProvider } from '@woocommerce/base-context';
|
2020-06-05 12:18:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { BLOCK_NAME } from './constants';
|
2020-05-27 14:45:18 +00:00
|
|
|
|
2020-09-20 23:54:08 +00:00
|
|
|
/** @typedef {import('react')} React */
|
|
|
|
|
2020-05-27 14:45:18 +00:00
|
|
|
/**
|
|
|
|
* The Single Product Block.
|
2020-09-20 23:54:08 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Incoming props for the component.
|
|
|
|
* @param {boolean} props.isLoading
|
|
|
|
* @param {Object} props.product
|
|
|
|
* @param {React.ReactChildren} props.children
|
2020-05-27 14:45:18 +00:00
|
|
|
*/
|
2020-06-05 12:18:16 +00:00
|
|
|
const Block = ( { isLoading, product, children } ) => {
|
2020-07-22 12:20:54 +00:00
|
|
|
const className = 'wc-block-single-product wc-block-layout';
|
2020-07-30 10:57:22 +00:00
|
|
|
const noticeContext = `woocommerce/single-product/${ product?.id || 0 }`;
|
2020-06-05 12:18:16 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<InnerBlockLayoutContextProvider
|
|
|
|
parentName={ BLOCK_NAME }
|
|
|
|
parentClassName={ className }
|
|
|
|
>
|
2020-07-22 12:20:54 +00:00
|
|
|
<ProductDataContextProvider
|
|
|
|
product={ product }
|
|
|
|
isLoading={ isLoading }
|
|
|
|
>
|
2020-07-30 10:57:22 +00:00
|
|
|
<StoreNoticesProvider context={ noticeContext }>
|
|
|
|
<div className={ className }>{ children }</div>
|
|
|
|
</StoreNoticesProvider>
|
2020-06-05 12:18:16 +00:00
|
|
|
</ProductDataContextProvider>
|
|
|
|
</InnerBlockLayoutContextProvider>
|
|
|
|
);
|
2020-05-27 14:45:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default withProduct( Block );
|