2022-11-15 19:19:58 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-11-18 17:51:01 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/settings';
|
2022-11-15 19:19:58 +00:00
|
|
|
import {
|
|
|
|
Product,
|
|
|
|
PRODUCTS_STORE_NAME,
|
|
|
|
WCDataSelector,
|
|
|
|
} from '@woocommerce/data';
|
|
|
|
import { useFormContext } from '@woocommerce/components';
|
|
|
|
import { useParams } from 'react-router-dom';
|
|
|
|
import { useSelect } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getProductTitle } from './utils/get-product-title';
|
2022-11-18 17:51:01 +00:00
|
|
|
import { ProductBreadcrumbs } from './product-breadcrumbs';
|
2022-11-16 16:03:39 +00:00
|
|
|
import { ProductStatusBadge } from './product-status-badge';
|
2022-11-15 19:19:58 +00:00
|
|
|
import { WooHeaderPageTitle } from '~/header/utils';
|
2022-11-24 14:00:20 +00:00
|
|
|
import './product-title.scss';
|
2022-11-15 19:19:58 +00:00
|
|
|
|
|
|
|
export const ProductTitle: React.FC = () => {
|
|
|
|
const { values } = useFormContext< Product >();
|
|
|
|
const { productId } = useParams();
|
|
|
|
const { persistedName } = useSelect( ( select: WCDataSelector ) => {
|
|
|
|
const product = productId
|
|
|
|
? select( PRODUCTS_STORE_NAME ).getProduct(
|
|
|
|
parseInt( productId, 10 ),
|
|
|
|
undefined
|
|
|
|
)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
persistedName: product?.name,
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
2022-11-18 17:51:01 +00:00
|
|
|
const breadcrumbs = [
|
|
|
|
{
|
|
|
|
href: getAdminLink( 'edit.php?post_type=product' ),
|
|
|
|
title: __( 'Products', 'woocommerce' ),
|
|
|
|
},
|
|
|
|
];
|
2022-11-15 19:19:58 +00:00
|
|
|
const title = getProductTitle( values.name, values.type, persistedName );
|
|
|
|
|
2022-11-16 16:03:39 +00:00
|
|
|
return (
|
|
|
|
<WooHeaderPageTitle>
|
2022-11-24 14:00:20 +00:00
|
|
|
<span className="woocommerce-product-title">
|
|
|
|
<ProductBreadcrumbs breadcrumbs={ breadcrumbs } />
|
|
|
|
<span className="woocommerce-product-title__wrapper">
|
|
|
|
{ title }
|
|
|
|
<ProductStatusBadge />
|
|
|
|
</span>
|
|
|
|
</span>
|
2022-11-16 16:03:39 +00:00
|
|
|
</WooHeaderPageTitle>
|
|
|
|
);
|
2022-11-15 19:19:58 +00:00
|
|
|
};
|