2023-03-08 09:51:59 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-03-09 21:11:25 +00:00
|
|
|
import {
|
|
|
|
__experimentalEditor as Editor,
|
2023-05-16 10:41:26 +00:00
|
|
|
__experimentalInitBlocks as initBlocks,
|
2023-10-12 19:59:13 +00:00
|
|
|
__experimentalWooProductMoreMenuItem as WooProductMoreMenuItem,
|
2023-03-10 20:21:22 +00:00
|
|
|
ProductEditorSettings,
|
2023-04-13 15:45:50 +00:00
|
|
|
productApiFetchMiddleware,
|
2023-07-12 20:01:06 +00:00
|
|
|
TRACKS_SOURCE,
|
2023-10-12 14:56:48 +00:00
|
|
|
__experimentalProductMVPCESFooter as FeedbackBar,
|
|
|
|
__experimentalProductMVPFeedbackModalContainer as ProductMVPFeedbackModalContainer,
|
2023-10-23 16:47:26 +00:00
|
|
|
ProductPageSkeleton,
|
2023-03-09 21:11:25 +00:00
|
|
|
} from '@woocommerce/product-editor';
|
2023-07-12 20:01:06 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2023-05-16 10:41:26 +00:00
|
|
|
import { useEffect } from '@wordpress/element';
|
2023-10-13 20:22:11 +00:00
|
|
|
import { registerPlugin, unregisterPlugin } from '@wordpress/plugins';
|
2023-03-09 21:11:25 +00:00
|
|
|
import { useParams } from 'react-router-dom';
|
2023-10-12 14:56:48 +00:00
|
|
|
import { WooFooterItem } from '@woocommerce/admin-layout';
|
2023-03-08 09:51:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-03-22 07:48:55 +00:00
|
|
|
import { useProductEntityRecord } from './hooks/use-product-entity-record';
|
2023-06-06 15:06:26 +00:00
|
|
|
import BlockEditorTourWrapper from './tour/block-editor/block-editor-tour-wrapper';
|
2023-10-12 19:59:13 +00:00
|
|
|
import { MoreMenuFill } from './fills/product-block-editor-fills';
|
|
|
|
import './product-page.scss';
|
2023-03-08 09:51:59 +00:00
|
|
|
|
2023-03-10 20:21:22 +00:00
|
|
|
declare const productBlockEditorSettings: ProductEditorSettings;
|
|
|
|
|
2023-04-13 15:45:50 +00:00
|
|
|
productApiFetchMiddleware();
|
|
|
|
|
2023-03-22 07:48:55 +00:00
|
|
|
export default function ProductPage() {
|
|
|
|
const { productId } = useParams();
|
|
|
|
|
|
|
|
const product = useProductEntityRecord( productId );
|
|
|
|
|
2023-05-16 10:41:26 +00:00
|
|
|
useEffect( () => {
|
2023-10-13 20:22:11 +00:00
|
|
|
registerPlugin( 'wc-admin-more-menu', {
|
|
|
|
// @ts-expect-error 'scope' does exist. @types/wordpress__plugins is outdated.
|
|
|
|
scope: 'woocommerce-product-block-editor',
|
|
|
|
render: () => (
|
|
|
|
<>
|
|
|
|
<WooProductMoreMenuItem>
|
|
|
|
{ ( { onClose }: { onClose: () => void } ) => (
|
|
|
|
<MoreMenuFill onClose={ onClose } />
|
|
|
|
) }
|
|
|
|
</WooProductMoreMenuItem>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
|
|
|
const unregisterBlocks = initBlocks();
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
unregisterPlugin( 'wc-admin-more-menu' );
|
|
|
|
unregisterBlocks();
|
|
|
|
};
|
2023-05-16 10:41:26 +00:00
|
|
|
}, [] );
|
|
|
|
|
2023-07-12 20:01:06 +00:00
|
|
|
useEffect(
|
|
|
|
function trackViewEvents() {
|
|
|
|
if ( productId ) {
|
|
|
|
recordEvent( 'product_edit_view', {
|
|
|
|
source: TRACKS_SOURCE,
|
|
|
|
product_id: productId,
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
recordEvent( 'product_add_view', {
|
|
|
|
source: TRACKS_SOURCE,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[ productId ]
|
|
|
|
);
|
|
|
|
|
2023-03-15 16:44:05 +00:00
|
|
|
if ( ! product?.id ) {
|
2023-10-23 16:47:26 +00:00
|
|
|
return <ProductPageSkeleton />;
|
2023-03-09 21:11:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-10 20:21:22 +00:00
|
|
|
return (
|
2023-06-06 15:06:26 +00:00
|
|
|
<>
|
|
|
|
<Editor
|
|
|
|
product={ product }
|
|
|
|
settings={ productBlockEditorSettings || {} }
|
|
|
|
/>
|
2023-10-12 14:56:48 +00:00
|
|
|
<WooFooterItem>
|
|
|
|
<>
|
|
|
|
<FeedbackBar productType="product" />
|
|
|
|
<ProductMVPFeedbackModalContainer
|
|
|
|
productId={ product.id }
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
</WooFooterItem>
|
2023-06-06 15:06:26 +00:00
|
|
|
<BlockEditorTourWrapper />
|
|
|
|
</>
|
2023-03-10 20:21:22 +00:00
|
|
|
);
|
2023-03-08 09:51:59 +00:00
|
|
|
}
|