Load registered and recommended channels in MarketingOverviewMultichannel.
The data will be used to conditionally display Campaigns card later.
This commit is contained in:
parent
e950417542
commit
52dd8845cc
|
@ -3,65 +3,33 @@
|
||||||
*/
|
*/
|
||||||
import { Fragment } from '@wordpress/element';
|
import { Fragment } from '@wordpress/element';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Card, CardHeader, CardBody, CardDivider } from '@wordpress/components';
|
import { Card, CardHeader, CardDivider } from '@wordpress/components';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import {
|
import { CardHeaderTitle, CardHeaderDescription } from '~/marketing/components';
|
||||||
CardHeaderTitle,
|
import { InstalledChannel, RecommendedChannel } from '~/marketing/types';
|
||||||
CardHeaderDescription,
|
|
||||||
CenteredSpinner,
|
|
||||||
} from '~/marketing/components';
|
|
||||||
import {
|
|
||||||
useRegisteredChannels,
|
|
||||||
useRecommendedChannels,
|
|
||||||
} from '~/marketing/hooks';
|
|
||||||
import { InstalledChannelCardBody } from './InstalledChannelCardBody';
|
import { InstalledChannelCardBody } from './InstalledChannelCardBody';
|
||||||
import { RecommendedChannels } from './RecommendedChannels';
|
import { RecommendedChannels } from './RecommendedChannels';
|
||||||
import { RecommendedChannelsList } from './RecommendedChannelsList';
|
import { RecommendedChannelsList } from './RecommendedChannelsList';
|
||||||
import './Channels.scss';
|
import './Channels.scss';
|
||||||
|
|
||||||
export const Channels = () => {
|
type ChannelsProps = {
|
||||||
const { loading: loadingRegistered, data: dataRegistered } =
|
registeredChannels: Array< InstalledChannel >;
|
||||||
useRegisteredChannels();
|
recommendedChannels: Array< RecommendedChannel >;
|
||||||
const { loading: loadingRecommended, data: dataRecommended } =
|
};
|
||||||
useRecommendedChannels();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: we may need to filter the channels against
|
|
||||||
* `@woocommerce/data` installed plugins.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( loadingRegistered || loadingRecommended ) {
|
|
||||||
return (
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardHeaderTitle>
|
|
||||||
{ __( 'Channels', 'woocommerce' ) }
|
|
||||||
</CardHeaderTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardBody>
|
|
||||||
<CenteredSpinner />
|
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export const Channels: React.FC< ChannelsProps > = ( {
|
||||||
|
registeredChannels,
|
||||||
|
recommendedChannels,
|
||||||
|
} ) => {
|
||||||
/*
|
/*
|
||||||
* If users have no registered channels,
|
* If users have no registered channels,
|
||||||
* we should display recommended channels without collapsible list
|
* we should display recommended channels without collapsible list
|
||||||
* and with a description in the card header.
|
* and with a description in the card header.
|
||||||
*/
|
*/
|
||||||
if ( dataRegistered.length === 0 ) {
|
if ( registeredChannels.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 (
|
return (
|
||||||
<Card className="woocommerce-marketing-channels-card">
|
<Card className="woocommerce-marketing-channels-card">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
|
@ -76,7 +44,7 @@ export const Channels = () => {
|
||||||
</CardHeaderDescription>
|
</CardHeaderDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<RecommendedChannelsList
|
<RecommendedChannelsList
|
||||||
recommendedChannels={ dataRecommended }
|
recommendedChannels={ recommendedChannels }
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
@ -97,18 +65,22 @@ export const Channels = () => {
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
{ /* Registered channels section. */ }
|
{ /* Registered channels section. */ }
|
||||||
{ dataRegistered.map( ( el, idx ) => {
|
{ registeredChannels.map( ( el, idx ) => {
|
||||||
return (
|
return (
|
||||||
<Fragment key={ el.slug }>
|
<Fragment key={ el.slug }>
|
||||||
<InstalledChannelCardBody installedChannel={ el } />
|
<InstalledChannelCardBody installedChannel={ el } />
|
||||||
{ idx < dataRegistered.length - 1 && <CardDivider /> }
|
{ idx < registeredChannels.length - 1 && (
|
||||||
|
<CardDivider />
|
||||||
|
) }
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
} ) }
|
} ) }
|
||||||
|
|
||||||
{ /* Recommended channels section. */ }
|
{ /* Recommended channels section. */ }
|
||||||
{ dataRecommended.length > 0 && (
|
{ recommendedChannels.length >= 1 && (
|
||||||
<RecommendedChannels recommendedChannels={ dataRecommended } />
|
<RecommendedChannels
|
||||||
|
recommendedChannels={ recommendedChannels }
|
||||||
|
/>
|
||||||
) }
|
) }
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|
|
@ -12,18 +12,36 @@ import { InstalledExtensions } from './InstalledExtensions';
|
||||||
import { DiscoverTools } from './DiscoverTools';
|
import { DiscoverTools } from './DiscoverTools';
|
||||||
import { LearnMarketing } from './LearnMarketing';
|
import { LearnMarketing } from './LearnMarketing';
|
||||||
import '~/marketing/data';
|
import '~/marketing/data';
|
||||||
|
import {
|
||||||
|
useRegisteredChannels,
|
||||||
|
useRecommendedChannels,
|
||||||
|
} from '~/marketing/hooks';
|
||||||
import './MarketingOverviewMultichannel.scss';
|
import './MarketingOverviewMultichannel.scss';
|
||||||
|
import { CenteredSpinner } from '../components';
|
||||||
|
|
||||||
export const MarketingOverviewMultichannel: React.FC = () => {
|
export const MarketingOverviewMultichannel: React.FC = () => {
|
||||||
|
const { loading: loadingRegistered, data: dataRegistered } =
|
||||||
|
useRegisteredChannels();
|
||||||
|
const { loading: loadingRecommended, data: dataRecommended } =
|
||||||
|
useRecommendedChannels();
|
||||||
const { currentUserCan } = useUser();
|
const { currentUserCan } = useUser();
|
||||||
|
|
||||||
const shouldShowExtensions =
|
const shouldShowExtensions =
|
||||||
getAdminSetting( 'allowMarketplaceSuggestions', false ) &&
|
getAdminSetting( 'allowMarketplaceSuggestions', false ) &&
|
||||||
currentUserCan( 'install_plugins' );
|
currentUserCan( 'install_plugins' );
|
||||||
|
|
||||||
|
if ( loadingRegistered || loadingRecommended ) {
|
||||||
|
return <CenteredSpinner />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="woocommerce-marketing-overview-multichannel">
|
<div className="woocommerce-marketing-overview-multichannel">
|
||||||
<Channels />
|
{ ( dataRegistered.length >= 1 || dataRecommended.length >= 1 ) && (
|
||||||
|
<Channels
|
||||||
|
registeredChannels={ dataRegistered }
|
||||||
|
recommendedChannels={ dataRecommended }
|
||||||
|
/>
|
||||||
|
) }
|
||||||
<InstalledExtensions />
|
<InstalledExtensions />
|
||||||
{ shouldShowExtensions && <DiscoverTools /> }
|
{ shouldShowExtensions && <DiscoverTools /> }
|
||||||
<LearnMarketing />
|
<LearnMarketing />
|
||||||
|
|
Loading…
Reference in New Issue