/** * External dependencies */ import { __, _n, sprintf } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; import { Button, PanelBody, Placeholder, withSpokenMessages, } from '@wordpress/components'; import { SearchListItem } from '@woocommerce/editor-components/search-list-control'; import ProductControl from '@woocommerce/editor-components/product-control'; import { commentContent, Icon } from '@wordpress/icons'; /** * Internal dependencies */ import EditorContainerBlock from '../editor-container-block'; import NoReviewsPlaceholder from './no-reviews-placeholder.js'; import { getBlockControls, getSharedReviewContentControls, getSharedReviewListControls, } from '../edit-utils.js'; import { ReviewsByProductEditorProps } from './types'; const ReviewsByProductEditor = ( { attributes, debouncedSpeak, setAttributes, }: ReviewsByProductEditorProps ) => { const { editMode, productId } = attributes; const renderProductControlItem = ( args ) => { const { item = 0 } = args; return ( ); }; const getInspectorControls = () => { return ( { const id = value[ 0 ] ? value[ 0 ].id : 0; setAttributes( { productId: id } ); } } renderItem={ renderProductControlItem } isCompact={ true } /> { getSharedReviewContentControls( attributes, setAttributes ) } { getSharedReviewListControls( attributes, setAttributes ) } ); }; const renderEditMode = () => { const onDone = () => { setAttributes( { editMode: false } ); debouncedSpeak( __( 'Showing Reviews by Product block preview.', 'woo-gutenberg-products-block' ) ); }; return ( } label={ __( 'Reviews by Product', 'woo-gutenberg-products-block' ) } className="wc-block-reviews-by-product" > { __( 'Show reviews of your product to build trust', 'woo-gutenberg-products-block' ) }
{ const id = value[ 0 ] ? value[ 0 ].id : 0; setAttributes( { productId: id } ); } } queryArgs={ { orderby: 'comment_count', order: 'desc', } } renderItem={ renderProductControlItem } />
); }; if ( ! productId || editMode ) { return renderEditMode(); } const buttonTitle = __( 'Edit selected product', 'woo-gutenberg-products-block' ); return ( <> { getBlockControls( editMode, setAttributes, buttonTitle ) } { getInspectorControls() } } name={ __( 'Reviews by Product', 'woo-gutenberg-products-block' ) } noReviewsPlaceholder={ NoReviewsPlaceholder } /> ); }; export default withSpokenMessages( ReviewsByProductEditor );