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-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-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-03-09 21:11:25 +00:00
|
|
|
import { Spinner } from '@wordpress/components';
|
2023-05-16 10:41:26 +00:00
|
|
|
import { useEffect } from '@wordpress/element';
|
2023-03-09 21:11:25 +00:00
|
|
|
import { useParams } from 'react-router-dom';
|
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-03-22 10:30:06 +00:00
|
|
|
import './fills/product-block-editor-fills';
|
2023-05-18 08:25:36 +00:00
|
|
|
import './product-page.scss';
|
2023-06-06 15:06:26 +00:00
|
|
|
import BlockEditorTourWrapper from './tour/block-editor/block-editor-tour-wrapper';
|
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( () => {
|
|
|
|
return initBlocks();
|
|
|
|
}, [] );
|
|
|
|
|
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-03-09 21:11:25 +00:00
|
|
|
return <Spinner />;
|
|
|
|
}
|
|
|
|
|
2023-03-10 20:21:22 +00:00
|
|
|
return (
|
2023-06-06 15:06:26 +00:00
|
|
|
<>
|
|
|
|
<Editor
|
|
|
|
product={ product }
|
|
|
|
settings={ productBlockEditorSettings || {} }
|
|
|
|
/>
|
|
|
|
<BlockEditorTourWrapper />
|
|
|
|
</>
|
2023-03-10 20:21:22 +00:00
|
|
|
);
|
2023-03-08 09:51:59 +00:00
|
|
|
}
|