2020-06-12 07:17:17 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-07-28 02:32:58 +00:00
|
|
|
import './style.scss';
|
2020-06-12 07:17:17 +00:00
|
|
|
import RecommendedExtensionsItem from './item';
|
2020-11-23 10:15:07 +00:00
|
|
|
import RecommendedExtensionsPlaceholder from './placeholder';
|
2020-06-12 07:17:17 +00:00
|
|
|
import { STORE_KEY } from '../../data/constants';
|
2020-10-23 06:41:45 +00:00
|
|
|
import Card from '../card';
|
2020-06-12 07:17:17 +00:00
|
|
|
|
|
|
|
const RecommendedExtensions = ( {
|
|
|
|
extensions,
|
|
|
|
isLoading,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
category,
|
|
|
|
} ) => {
|
|
|
|
if ( extensions.length === 0 && ! isLoading ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-28 02:32:58 +00:00
|
|
|
const categoryClass = category
|
|
|
|
? `woocommerce-marketing-recommended-extensions-card__category-${ category }`
|
|
|
|
: '';
|
2020-11-23 10:15:07 +00:00
|
|
|
const placholdersCount = 5;
|
2020-06-12 07:17:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
title={ title }
|
|
|
|
description={ description }
|
|
|
|
className={ classnames(
|
|
|
|
'woocommerce-marketing-recommended-extensions-card',
|
2020-07-28 02:32:58 +00:00
|
|
|
categoryClass
|
2020-06-12 07:17:17 +00:00
|
|
|
) }
|
|
|
|
>
|
2020-10-23 06:41:45 +00:00
|
|
|
{ isLoading ? (
|
2020-11-23 10:15:07 +00:00
|
|
|
<div
|
|
|
|
className={ classnames(
|
|
|
|
'woocommerce-marketing-recommended-extensions-card__items',
|
|
|
|
`woocommerce-marketing-recommended-extensions-card__items--count-${ placholdersCount }`
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
{ [ ...Array( placholdersCount ).keys() ].map( ( key ) => (
|
|
|
|
<RecommendedExtensionsPlaceholder key={ key } />
|
|
|
|
) ) }
|
|
|
|
</div>
|
2020-10-23 06:41:45 +00:00
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className={ classnames(
|
|
|
|
'woocommerce-marketing-recommended-extensions-card__items',
|
|
|
|
`woocommerce-marketing-recommended-extensions-card__items--count-${ extensions.length }`
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
{ extensions.map( ( extension ) => (
|
|
|
|
<RecommendedExtensionsItem
|
|
|
|
key={ extension.product }
|
|
|
|
category={ category }
|
|
|
|
{ ...extension }
|
|
|
|
/>
|
|
|
|
) ) }
|
|
|
|
</div>
|
|
|
|
) }
|
2020-06-12 07:17:17 +00:00
|
|
|
</Card>
|
2020-07-28 02:32:58 +00:00
|
|
|
);
|
|
|
|
};
|
2020-06-12 07:17:17 +00:00
|
|
|
|
|
|
|
RecommendedExtensions.propTypes = {
|
|
|
|
/**
|
|
|
|
* Array of recommended extensions.
|
|
|
|
*/
|
|
|
|
extensions: PropTypes.arrayOf( PropTypes.object ).isRequired,
|
|
|
|
/**
|
|
|
|
* Whether the card is loading.
|
|
|
|
*/
|
|
|
|
isLoading: PropTypes.bool.isRequired,
|
|
|
|
/**
|
|
|
|
* Cart title.
|
|
|
|
*/
|
|
|
|
title: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Card description.
|
|
|
|
*/
|
|
|
|
description: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Category of extensions to display.
|
|
|
|
*/
|
|
|
|
category: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
RecommendedExtensions.defaultProps = {
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Recommended extensions', 'woocommerce' ),
|
2020-07-28 02:32:58 +00:00
|
|
|
description: __(
|
|
|
|
'Great marketing requires the right tools. Take your marketing to the next level with our recommended marketing extensions.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2020-07-28 02:32:58 +00:00
|
|
|
),
|
2020-06-12 07:17:17 +00:00
|
|
|
};
|
|
|
|
|
2020-07-28 02:32:58 +00:00
|
|
|
export { RecommendedExtensions };
|
2020-11-23 10:15:07 +00:00
|
|
|
export { default as RecommendedExtensionsPlaceholder } from './placeholder';
|
2020-06-12 07:17:17 +00:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( ( select, props ) => {
|
|
|
|
const { getRecommendedPlugins, isResolving } = select( STORE_KEY );
|
|
|
|
|
|
|
|
return {
|
|
|
|
extensions: getRecommendedPlugins( props.category ),
|
2020-07-28 02:32:58 +00:00
|
|
|
isLoading: isResolving( 'getRecommendedPlugins', [
|
|
|
|
props.category,
|
|
|
|
] ),
|
2020-06-12 07:17:17 +00:00
|
|
|
};
|
|
|
|
} ),
|
|
|
|
withDispatch( ( dispatch ) => {
|
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
createNotice,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( RecommendedExtensions );
|