2023-10-05 18:27:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
__experimentalEditor as Editor,
|
|
|
|
__experimentalInitBlocks as initBlocks,
|
2023-10-12 19:59:13 +00:00
|
|
|
__experimentalWooProductMoreMenuItem as WooProductMoreMenuItem,
|
2023-10-05 18:27:54 +00:00
|
|
|
ProductEditorSettings,
|
|
|
|
productApiFetchMiddleware,
|
|
|
|
TRACKS_SOURCE,
|
2023-10-12 14:56:48 +00:00
|
|
|
__experimentalVariationSwitcherFooter as VariationSwitcherFooter,
|
2023-10-12 19:59:13 +00:00
|
|
|
__experimentalProductMVPFeedbackModalContainer as ProductMVPFeedbackModalContainer,
|
2023-10-05 18:27:54 +00:00
|
|
|
} from '@woocommerce/product-editor';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
import { Spinner } from '@wordpress/components';
|
|
|
|
import { useEffect } from '@wordpress/element';
|
2023-10-12 14:56:48 +00:00
|
|
|
import { WooFooterItem } from '@woocommerce/admin-layout';
|
2023-10-13 20:22:11 +00:00
|
|
|
import { registerPlugin, unregisterPlugin } from '@wordpress/plugins';
|
2023-10-05 18:27:54 +00:00
|
|
|
import { useParams } from 'react-router-dom';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-10-12 19:59:13 +00:00
|
|
|
import { MoreMenuFill } from './fills/product-block-editor-fills';
|
2023-10-05 18:27:54 +00:00
|
|
|
import { useProductVariationEntityRecord } from './hooks/use-product-variation-entity-record';
|
2023-10-12 19:59:13 +00:00
|
|
|
import { DeleteVariationMenuItem } from './fills/more-menu-items';
|
|
|
|
import './product-page.scss';
|
2023-10-05 18:27:54 +00:00
|
|
|
|
|
|
|
declare const productBlockEditorSettings: ProductEditorSettings;
|
|
|
|
|
|
|
|
productApiFetchMiddleware();
|
|
|
|
|
|
|
|
export default function ProductPage() {
|
|
|
|
const { productId, variationId } = useParams();
|
|
|
|
|
2023-10-12 19:59:13 +00:00
|
|
|
const variation = useProductVariationEntityRecord( variationId as string );
|
2023-10-05 18:27:54 +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 } ) => (
|
|
|
|
<>
|
|
|
|
<DeleteVariationMenuItem onClose={ onClose } />
|
|
|
|
<MoreMenuFill
|
|
|
|
productType="product_variation"
|
|
|
|
onClose={ onClose }
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) }
|
|
|
|
</WooProductMoreMenuItem>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
} );
|
|
|
|
|
|
|
|
const unregisterBlocks = initBlocks();
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
unregisterPlugin( 'wc-admin-more-menu' );
|
|
|
|
unregisterBlocks();
|
|
|
|
};
|
2023-10-05 18:27:54 +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-10-12 19:59:13 +00:00
|
|
|
if ( ! variation?.id ) {
|
2023-10-05 18:27:54 +00:00
|
|
|
return <Spinner />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Editor
|
2023-10-12 19:59:13 +00:00
|
|
|
product={ variation }
|
2023-10-05 18:27:54 +00:00
|
|
|
productType="product_variation"
|
|
|
|
settings={ productBlockEditorSettings || {} }
|
|
|
|
/>
|
2023-10-12 19:59:13 +00:00
|
|
|
<WooFooterItem order={ 0 }>
|
|
|
|
<>
|
2023-10-12 14:56:48 +00:00
|
|
|
<VariationSwitcherFooter
|
2023-10-12 19:59:13 +00:00
|
|
|
parentId={ variation.parent_id }
|
|
|
|
variationId={ variation.id }
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ProductMVPFeedbackModalContainer
|
|
|
|
productId={ variation.parent_id }
|
2023-10-12 14:56:48 +00:00
|
|
|
/>
|
2023-10-12 19:59:13 +00:00
|
|
|
</>
|
|
|
|
</WooFooterItem>
|
2023-10-05 18:27:54 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|