/** * External dependencies */ import { Fragment } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Card, CardHeader, CardBody, CardDivider } from '@wordpress/components'; /** * Internal dependencies */ import { CardHeaderTitle, CardHeaderDescription, CenteredSpinner, } from '~/marketing/components'; import { useRegisteredChannels, useRecommendedChannels, } from '~/marketing/hooks'; import { InstalledChannelCardBody } from './InstalledChannelCardBody'; import { RecommendedChannels } from './RecommendedChannels'; import { RecommendedChannelsList } from './RecommendedChannelsList'; import './Channels.scss'; export const Channels = () => { const { loading: loadingRegistered, data: dataRegistered } = useRegisteredChannels(); const { loading: loadingRecommended, data: dataRecommended } = useRecommendedChannels(); /** * TODO: we may need to filter the channels against * `@woocommerce/data` installed plugins. */ if ( loadingRegistered || loadingRecommended ) { return ( { __( 'Channels', 'woocommerce' ) } ); } /* * If users have no registered channels, * we should display recommended channels without collapsible list * and with a description in the card header. */ if ( dataRegistered.length === 0 ) { /** * If for some reasons we don't have recommended channels, * then we should not show the Channels card at all. */ if ( dataRecommended.length === 0 ) { return null; } return ( { __( 'Channels', 'woocommerce' ) } { __( 'Start by adding a channel to your store', 'woocommerce' ) } ); } /* * Users have registered channels, * so here we display the registered channels first. * If there are recommended channels, * we display them next in a collapsible list. */ return ( { __( 'Channels', 'woocommerce' ) } { /* Registered channels section. */ } { dataRegistered.map( ( el, idx ) => { return ( { idx < dataRegistered.length - 1 && } ); } ) } { /* Recommended channels section. */ } { dataRecommended.length > 0 && ( ) } ); };