2018-07-09 15:46:31 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2018-08-01 12:21:51 +00:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2018-07-20 18:24:39 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-07-25 14:25:08 +00:00
|
|
|
import Gridicon from 'gridicons';
|
2018-08-01 12:21:51 +00:00
|
|
|
import interpolateComponents from 'interpolate-components';
|
|
|
|
import { noop } from 'lodash';
|
2018-07-09 15:46:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-08-01 12:21:51 +00:00
|
|
|
import { ActivityCard, ActivityCardPlaceholder } from '../activity-card';
|
2018-07-16 18:37:25 +00:00
|
|
|
import ActivityHeader from '../activity-header';
|
2018-08-01 12:21:51 +00:00
|
|
|
import Gravatar from 'components/gravatar';
|
|
|
|
import Link from 'components/link';
|
|
|
|
import ProductImage from 'components/product-image';
|
|
|
|
import { ReviewRating } from 'components/rating';
|
|
|
|
import { Section } from 'layout/section';
|
2018-07-25 14:25:08 +00:00
|
|
|
import SplitButton from 'components/split-button';
|
2018-07-09 15:46:31 +00:00
|
|
|
|
2018-08-01 12:21:51 +00:00
|
|
|
// TODO Pull proper data from the API
|
|
|
|
const demoReviews = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
product_id: 1,
|
|
|
|
reviewer: 'Justin Shreve',
|
|
|
|
reviewer_email: 'justin@automattic.com',
|
|
|
|
rating: 3,
|
|
|
|
verified: true,
|
|
|
|
review:
|
|
|
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque finibus hendrerit finibus.' +
|
|
|
|
'Integer tristique turpis a aliquam aliquam. Phasellus sapien lectus, sodales in sagittis nec, placerat a augue.',
|
|
|
|
status: 'pending',
|
|
|
|
date_created: '2018-07-10T02:49:00Z',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const demoProducts = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
name: 'WordPress Shirt',
|
|
|
|
permalink: '#',
|
|
|
|
images: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
src: 'https://cldup.com/5QyaPgyfFo-3000x3000.png',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-07-09 15:46:31 +00:00
|
|
|
class ReviewsPanel extends Component {
|
2018-08-01 12:21:51 +00:00
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
reviews: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.interval = setTimeout( () => {
|
|
|
|
this.setState( {
|
|
|
|
loading: false,
|
|
|
|
reviews: demoReviews,
|
|
|
|
} );
|
|
|
|
}, 5000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearTimeout( this.interval );
|
|
|
|
}
|
|
|
|
|
|
|
|
renderReview( review ) {
|
|
|
|
const product = demoProducts[ 0 ];
|
|
|
|
|
|
|
|
const title = interpolateComponents( {
|
|
|
|
mixedString: sprintf(
|
|
|
|
__(
|
|
|
|
'{{productLink}}%s{{/productLink}} reviewed by {{authorLink}}%s{{/authorLink}}',
|
|
|
|
'wc-admin'
|
|
|
|
),
|
|
|
|
product.name,
|
|
|
|
review.reviewer
|
|
|
|
),
|
|
|
|
components: {
|
|
|
|
productLink: <Link href={ product.permalink } type="external" />,
|
|
|
|
authorLink: <Link href={ 'mailto:' + review.reviewer_email } type="external" />,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
const subtitle = (
|
2018-07-20 18:24:39 +00:00
|
|
|
<Fragment>
|
2018-08-01 12:21:51 +00:00
|
|
|
<ReviewRating review={ review } />
|
|
|
|
{ review.verified && (
|
|
|
|
<span className="woocommerce-review-activity-card__verified">
|
|
|
|
<Gridicon icon="checkmark" size={ 18 } />
|
|
|
|
{ __( 'Verified customer', 'wc-admin' ) }
|
|
|
|
</span>
|
|
|
|
) }
|
|
|
|
</Fragment>
|
|
|
|
);
|
2018-07-25 14:25:08 +00:00
|
|
|
|
2018-08-01 12:21:51 +00:00
|
|
|
const icon = (
|
|
|
|
<div className="woocommerce-review-activity-card__image-overlay">
|
|
|
|
<Gravatar user={ review.reviewer_email } size={ 24 } />
|
|
|
|
<ProductImage product={ product } />
|
|
|
|
</div>
|
|
|
|
);
|
2018-07-25 14:25:08 +00:00
|
|
|
|
2018-08-01 12:21:51 +00:00
|
|
|
const cardActions = () => {
|
|
|
|
const mainLabel =
|
|
|
|
'approved' === review.status ? __( 'Unapprove', 'wc-admin' ) : __( 'Approve', 'wc-admin' );
|
|
|
|
return (
|
2018-07-25 14:25:08 +00:00
|
|
|
<SplitButton
|
2018-08-01 12:21:51 +00:00
|
|
|
mainLabel={ mainLabel }
|
|
|
|
menuLabel={ __( 'Select an action', 'wc-admin' ) }
|
|
|
|
onClick={ noop }
|
2018-07-25 14:25:08 +00:00
|
|
|
controls={ [
|
|
|
|
{
|
2018-08-01 12:21:51 +00:00
|
|
|
label: __( 'Reply', 'wc-admin' ),
|
|
|
|
onClick: noop,
|
2018-07-25 14:25:08 +00:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 12:21:51 +00:00
|
|
|
label: __( 'Spam', 'wc-admin' ),
|
|
|
|
onClick: noop,
|
2018-07-25 14:25:08 +00:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 12:21:51 +00:00
|
|
|
label: __( 'Trash', 'wc-admin' ),
|
|
|
|
onClick: noop,
|
2018-07-25 14:25:08 +00:00
|
|
|
},
|
|
|
|
] }
|
|
|
|
/>
|
2018-08-01 12:21:51 +00:00
|
|
|
);
|
|
|
|
};
|
2018-07-25 14:25:08 +00:00
|
|
|
|
2018-08-01 12:21:51 +00:00
|
|
|
return (
|
|
|
|
<ActivityCard
|
|
|
|
className="woocommerce-review-activity-card"
|
|
|
|
key={ review.id }
|
|
|
|
title={ title }
|
|
|
|
subtitle={ subtitle }
|
|
|
|
date={ review.date_created }
|
|
|
|
icon={ icon }
|
|
|
|
actions={ cardActions() }
|
|
|
|
>
|
|
|
|
{ review.review }
|
|
|
|
</ActivityCard>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { loading = true, reviews = [] } = this.state;
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ActivityHeader title={ __( 'Reviews', 'wc-admin' ) } />
|
|
|
|
<Section>
|
|
|
|
{ loading ? (
|
|
|
|
<ActivityCardPlaceholder hasAction hasSubtitle hasDate lines={ 2 } />
|
|
|
|
) : (
|
|
|
|
reviews.map( this.renderReview )
|
|
|
|
) }
|
|
|
|
</Section>
|
2018-07-20 18:24:39 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
2018-07-09 15:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReviewsPanel;
|