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

88 lines
2.3 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, CardDivider } from '@wordpress/components';
2022-12-08 15:53:36 +00:00
/**
* Internal dependencies
*/
import { CardHeaderTitle, CardHeaderDescription } from '~/marketing/components';
import { InstalledChannel, RecommendedChannel } from '~/marketing/types';
import { InstalledChannelCardBody } from './InstalledChannelCardBody';
import { RecommendedChannels } from './RecommendedChannels';
import { RecommendedChannelsList } from './RecommendedChannelsList';
import './Channels.scss';
2022-12-08 15:53:36 +00:00
type ChannelsProps = {
registeredChannels: Array< InstalledChannel >;
recommendedChannels: Array< RecommendedChannel >;
};
2022-12-08 15:53:36 +00:00
export const Channels: React.FC< ChannelsProps > = ( {
registeredChannels,
recommendedChannels,
} ) => {
/*
* 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 ( registeredChannels.length === 0 ) {
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={ recommendedChannels }
/>
</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. */ }
{ registeredChannels.map( ( el, idx ) => {
return (
<Fragment key={ el.slug }>
<InstalledChannelCardBody installedChannel={ el } />
{ idx < registeredChannels.length - 1 && (
<CardDivider />
) }
</Fragment>
);
} ) }
{ /* Recommended channels section. */ }
{ recommendedChannels.length >= 1 && (
<RecommendedChannels
recommendedChannels={ recommendedChannels }
/>
) }
2022-12-08 15:53:36 +00:00
</Card>
);
};