/** * 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 */ import './style.scss'; import RecommendedExtensionsItem from './item'; import RecommendedExtensionsPlaceholder from './placeholder'; import { STORE_KEY } from '~/marketing/data/constants'; import Card from '../card'; const RecommendedExtensions = ( { extensions, isLoading, title, description, category, } ) => { if ( extensions.length === 0 && ! isLoading ) { return null; } const categoryClass = category ? `woocommerce-marketing-recommended-extensions-card__category-${ category }` : ''; const placholdersCount = 5; return ( { isLoading ? (
{ [ ...Array( placholdersCount ).keys() ].map( ( key ) => ( ) ) }
) : (
{ extensions.map( ( extension ) => ( ) ) }
) }
); }; 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 = { title: __( 'Recommended extensions', 'woocommerce' ), description: __( 'Great marketing requires the right tools. Take your marketing to the next level with our recommended marketing extensions.', 'woocommerce' ), }; export { RecommendedExtensions }; export { default as RecommendedExtensionsPlaceholder } from './placeholder'; export default compose( withSelect( ( select, props ) => { const { getRecommendedPlugins, isResolving } = select( STORE_KEY ); return { extensions: getRecommendedPlugins( props.category ), isLoading: isResolving( 'getRecommendedPlugins', [ props.category, ] ), }; } ), withDispatch( ( dispatch ) => { const { createNotice } = dispatch( 'core/notices' ); return { createNotice, }; } ) )( RecommendedExtensions );