2019-11-08 16:30:11 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-02-17 16:31:55 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { __experimentalCreateInterpolateElement } from 'wordpress-element';
|
2019-08-19 14:13:07 +00:00
|
|
|
import {
|
|
|
|
Notice,
|
|
|
|
ToggleControl,
|
2019-08-23 14:48:48 +00:00
|
|
|
Toolbar,
|
2019-08-19 14:13:07 +00:00
|
|
|
RangeControl,
|
|
|
|
SelectControl,
|
|
|
|
} from '@wordpress/components';
|
2019-08-23 14:48:48 +00:00
|
|
|
import { BlockControls } from '@wordpress/editor';
|
2019-11-28 16:33:29 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/settings';
|
2019-09-05 15:09:31 +00:00
|
|
|
import {
|
2019-12-13 17:13:11 +00:00
|
|
|
REVIEW_RATINGS_ENABLED,
|
2019-09-05 15:09:31 +00:00
|
|
|
SHOW_AVATARS,
|
|
|
|
} from '@woocommerce/block-settings';
|
2019-10-06 12:36:15 +00:00
|
|
|
import ToggleButtonControl from '@woocommerce/block-components/toggle-button-control';
|
2019-08-19 14:13:07 +00:00
|
|
|
|
2019-08-23 14:48:48 +00:00
|
|
|
export const getBlockControls = ( editMode, setAttributes ) => (
|
|
|
|
<BlockControls>
|
|
|
|
<Toolbar
|
|
|
|
controls={ [
|
|
|
|
{
|
|
|
|
icon: 'edit',
|
|
|
|
title: __( 'Edit', 'woo-gutenberg-products-block' ),
|
|
|
|
onClick: () => setAttributes( { editMode: ! editMode } ),
|
|
|
|
isActive: editMode,
|
|
|
|
},
|
|
|
|
] }
|
|
|
|
/>
|
|
|
|
</BlockControls>
|
|
|
|
);
|
|
|
|
|
2019-08-19 14:13:07 +00:00
|
|
|
export const getSharedReviewContentControls = ( attributes, setAttributes ) => {
|
|
|
|
return (
|
2020-02-17 16:31:55 +00:00
|
|
|
<>
|
2019-08-19 14:13:07 +00:00
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Product rating', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ attributes.showReviewRating }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showReviewRating: ! attributes.showReviewRating,
|
|
|
|
} )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
2019-12-13 17:13:11 +00:00
|
|
|
{ attributes.showReviewRating && ! REVIEW_RATINGS_ENABLED && (
|
2019-09-09 10:52:48 +00:00
|
|
|
<Notice
|
|
|
|
className="wc-block-reviews__notice"
|
|
|
|
isDismissible={ false }
|
|
|
|
>
|
2020-02-17 16:31:55 +00:00
|
|
|
{ __experimentalCreateInterpolateElement(
|
|
|
|
__(
|
|
|
|
'Product rating is disabled in your <a>store settings</a>.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
a: (
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
<a
|
|
|
|
href={ getAdminLink(
|
|
|
|
'admin.php?page=wc-settings&tab=products'
|
|
|
|
) }
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
/>
|
2019-08-26 10:11:50 +00:00
|
|
|
),
|
2020-02-17 16:31:55 +00:00
|
|
|
}
|
|
|
|
) }
|
2019-08-19 14:13:07 +00:00
|
|
|
</Notice>
|
|
|
|
) }
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Reviewer name', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ attributes.showReviewerName }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showReviewerName: ! attributes.showReviewerName,
|
|
|
|
} )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Image', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ attributes.showReviewImage }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showReviewImage: ! attributes.showReviewImage,
|
|
|
|
} )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Review date', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ attributes.showReviewDate }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showReviewDate: ! attributes.showReviewDate,
|
|
|
|
} )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Review content', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ attributes.showReviewContent }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
showReviewContent: ! attributes.showReviewContent,
|
|
|
|
} )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
|
|
|
{ attributes.showReviewImage && (
|
2020-02-17 16:31:55 +00:00
|
|
|
<>
|
2019-08-19 14:13:07 +00:00
|
|
|
<ToggleButtonControl
|
2019-09-09 10:52:48 +00:00
|
|
|
label={ __(
|
|
|
|
'Review image',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-08-19 14:13:07 +00:00
|
|
|
value={ attributes.imageType }
|
|
|
|
options={ [
|
2019-09-05 15:09:31 +00:00
|
|
|
{
|
2019-09-09 10:52:48 +00:00
|
|
|
label: __(
|
|
|
|
'Reviewer photo',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
2019-09-05 15:09:31 +00:00
|
|
|
value: 'reviewer',
|
|
|
|
},
|
|
|
|
{
|
2019-09-09 10:52:48 +00:00
|
|
|
label: __(
|
|
|
|
'Product',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
2019-09-05 15:09:31 +00:00
|
|
|
value: 'product',
|
|
|
|
},
|
2019-08-19 14:13:07 +00:00
|
|
|
] }
|
2019-09-09 10:52:48 +00:00
|
|
|
onChange={ ( value ) =>
|
|
|
|
setAttributes( { imageType: value } )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
2019-09-05 15:09:31 +00:00
|
|
|
{ attributes.imageType === 'reviewer' && ! SHOW_AVATARS && (
|
|
|
|
<Notice
|
|
|
|
className="wc-block-reviews__notice"
|
|
|
|
isDismissible={ false }
|
|
|
|
>
|
2020-02-17 16:31:55 +00:00
|
|
|
{ __experimentalCreateInterpolateElement(
|
|
|
|
__(
|
|
|
|
'Reviewer photo is disabled in your <a>site settings</a>.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
a: (
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
|
|
<a
|
|
|
|
href={ getAdminLink(
|
|
|
|
'options-discussion.php'
|
|
|
|
) }
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
/>
|
2019-08-26 10:11:50 +00:00
|
|
|
),
|
2020-02-17 16:31:55 +00:00
|
|
|
}
|
|
|
|
) }
|
2019-08-19 14:13:07 +00:00
|
|
|
</Notice>
|
|
|
|
) }
|
2020-02-17 16:31:55 +00:00
|
|
|
</>
|
2019-08-19 14:13:07 +00:00
|
|
|
) }
|
2020-02-17 16:31:55 +00:00
|
|
|
</>
|
2019-08-19 14:13:07 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getSharedReviewListControls = ( attributes, setAttributes ) => {
|
|
|
|
const minPerPage = 1;
|
|
|
|
const maxPerPage = 20;
|
|
|
|
|
|
|
|
return (
|
2020-02-17 16:31:55 +00:00
|
|
|
<>
|
2019-08-19 14:13:07 +00:00
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Order by', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ attributes.showOrderby }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( { showOrderby: ! attributes.showOrderby } )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
|
|
|
<SelectControl
|
2019-09-05 15:09:31 +00:00
|
|
|
label={ __(
|
|
|
|
'Order Product Reviews by',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-08-19 14:13:07 +00:00
|
|
|
value={ attributes.orderby }
|
|
|
|
options={ [
|
|
|
|
{ label: 'Most recent', value: 'most-recent' },
|
|
|
|
{ label: 'Highest Rating', value: 'highest-rating' },
|
|
|
|
{ label: 'Lowest Rating', value: 'lowest-rating' },
|
|
|
|
] }
|
|
|
|
onChange={ ( orderby ) => setAttributes( { orderby } ) }
|
|
|
|
/>
|
|
|
|
<RangeControl
|
2019-09-05 15:09:31 +00:00
|
|
|
label={ __(
|
|
|
|
'Starting Number of Reviews',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-08-19 14:13:07 +00:00
|
|
|
value={ attributes.reviewsOnPageLoad }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ ( reviewsOnPageLoad ) =>
|
|
|
|
setAttributes( { reviewsOnPageLoad } )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
max={ maxPerPage }
|
|
|
|
min={ minPerPage }
|
|
|
|
/>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Load more', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ attributes.showLoadMore }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( { showLoadMore: ! attributes.showLoadMore } )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
/>
|
|
|
|
{ attributes.showLoadMore && (
|
|
|
|
<RangeControl
|
2019-09-09 10:52:48 +00:00
|
|
|
label={ __(
|
|
|
|
'Load More Reviews',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-08-19 14:13:07 +00:00
|
|
|
value={ attributes.reviewsOnLoadMore }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ ( reviewsOnLoadMore ) =>
|
|
|
|
setAttributes( { reviewsOnLoadMore } )
|
|
|
|
}
|
2019-08-19 14:13:07 +00:00
|
|
|
max={ maxPerPage }
|
|
|
|
min={ minPerPage }
|
|
|
|
/>
|
|
|
|
) }
|
2020-02-17 16:31:55 +00:00
|
|
|
</>
|
2019-08-19 14:13:07 +00:00
|
|
|
);
|
|
|
|
};
|