woocommerce/plugins/woocommerce-admin/client/marketing/overview-multichannel/Channels/Channels.tsx

116 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-12-08 15:53:36 +00:00
/**
* External dependencies
*/
import { Fragment } from '@wordpress/element';
2022-12-08 15:53:36 +00:00
import { __ } from '@wordpress/i18n';
import { Card, CardHeader, CardBody, CardDivider } from '@wordpress/components';
2022-12-08 15:53:36 +00:00
/**
* 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';
2022-12-08 15:53:36 +00:00
export const Channels = () => {
const { loading: loadingRegistered, data: dataRegistered } =
useRegisteredChannels();
const { loading: loadingRecommended, data: dataRecommended } =
useRecommendedChannels();
2022-12-08 15:53:36 +00:00
/**
* TODO: we may need to filter the channels against
* `@woocommerce/data` installed plugins.
*/
if ( loadingRegistered || loadingRecommended ) {
2022-12-08 15:53:36 +00:00
return (
<Card>
<CardHeader>
<CardHeaderTitle>
{ __( 'Channels', 'woocommerce' ) }
</CardHeaderTitle>
</CardHeader>
2022-12-08 15:53:36 +00:00
<CardBody>
2022-12-08 18:20:05 +00:00
<CenteredSpinner />
2022-12-08 15:53:36 +00:00
</CardBody>
</Card>
);
}
/*
* If users have no registered channels,
2022-12-23 13:19:00 +00:00
* we should display recommended channels without collapsible list
* and with a description in the card header.
*/
if ( dataRegistered.length === 0 ) {
2022-12-23 13:19:00 +00:00
/**
* If for some reasons we don't have recommended channels,
* then we should not show the Channels card at all.
*/
if ( dataRecommended.length === 0 ) {
2022-12-23 13:19:00 +00:00
return null;
}
return (
<Card className="woocommerce-marketing-channels-card">
<CardHeader>
<CardHeaderTitle>
{ __( 'Channels', 'woocommerce' ) }
</CardHeaderTitle>
<CardHeaderDescription>
{ __(
'Start by adding a channel to your store',
'woocommerce'
) }
</CardHeaderDescription>
</CardHeader>
<RecommendedChannelsList
recommendedChannels={ dataRecommended }
/>
</Card>
);
}
2022-12-08 15:53:36 +00:00
/*
* 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.
*/
2022-12-08 15:53:36 +00:00
return (
<Card className="woocommerce-marketing-channels-card">
<CardHeader>
<CardHeaderTitle>
{ __( 'Channels', 'woocommerce' ) }
</CardHeaderTitle>
</CardHeader>
{ /* Registered channels section. */ }
{ dataRegistered.map( ( el, idx ) => {
return (
<Fragment key={ el.slug }>
<InstalledChannelCardBody installedChannel={ el } />
{ idx < dataRegistered.length - 1 && <CardDivider /> }
</Fragment>
);
} ) }
{ /* Recommended channels section. */ }
{ dataRecommended.length > 0 && (
<RecommendedChannels recommendedChannels={ dataRecommended } />
) }
2022-12-08 15:53:36 +00:00
</Card>
);
};