2022-12-08 15:53:36 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-01-27 17:12:36 +00:00
|
|
|
import { Fragment, useState } from '@wordpress/element';
|
2022-12-08 15:53:36 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2023-01-27 17:12:36 +00:00
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
CardHeader,
|
|
|
|
CardBody,
|
|
|
|
CardDivider,
|
|
|
|
Button,
|
|
|
|
Icon,
|
|
|
|
} from '@wordpress/components';
|
|
|
|
import { chevronUp, chevronDown } from '@wordpress/icons';
|
2022-12-08 15:53:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-01-20 18:20:06 +00:00
|
|
|
import { RecommendedChannel } from '~/marketing/data-multichannel/types';
|
2023-01-27 17:12:36 +00:00
|
|
|
import {
|
|
|
|
CardHeaderTitle,
|
|
|
|
CardHeaderDescription,
|
|
|
|
SmartPluginCardBody,
|
|
|
|
} from '~/marketing/components';
|
2023-01-20 18:36:39 +00:00
|
|
|
import { RegisteredChannel } from '~/marketing/types';
|
|
|
|
import { RegisteredChannelCardBody } from './RegisteredChannelCardBody';
|
2022-12-23 16:32:23 +00:00
|
|
|
import './Channels.scss';
|
2022-12-08 15:53:36 +00:00
|
|
|
|
2022-12-23 17:14:02 +00:00
|
|
|
type ChannelsProps = {
|
2023-01-20 18:36:39 +00:00
|
|
|
registeredChannels: Array< RegisteredChannel >;
|
2022-12-23 17:14:02 +00:00
|
|
|
recommendedChannels: Array< RecommendedChannel >;
|
2023-01-19 17:02:41 +00:00
|
|
|
onInstalledAndActivated?: () => void;
|
2022-12-23 17:14:02 +00:00
|
|
|
};
|
2022-12-08 15:53:36 +00:00
|
|
|
|
2022-12-23 17:14:02 +00:00
|
|
|
export const Channels: React.FC< ChannelsProps > = ( {
|
|
|
|
registeredChannels,
|
|
|
|
recommendedChannels,
|
2023-01-19 17:02:41 +00:00
|
|
|
onInstalledAndActivated,
|
2022-12-23 17:14:02 +00:00
|
|
|
} ) => {
|
2023-01-27 17:12:36 +00:00
|
|
|
/**
|
|
|
|
* State to collapse / expand the recommended channels.
|
|
|
|
*/
|
|
|
|
const [ expanded, setExpanded ] = useState(
|
|
|
|
registeredChannels.length === 0
|
|
|
|
);
|
|
|
|
|
2022-12-09 16:51:57 +00:00
|
|
|
/*
|
|
|
|
* If users have no registered channels,
|
2022-12-23 13:19:00 +00:00
|
|
|
* we should display recommended channels without collapsible list
|
2022-12-13 17:13:00 +00:00
|
|
|
* and with a description in the card header.
|
2022-12-09 16:51:57 +00:00
|
|
|
*/
|
2022-12-23 17:14:02 +00:00
|
|
|
if ( registeredChannels.length === 0 ) {
|
2022-12-09 16:51:57 +00:00
|
|
|
return (
|
|
|
|
<Card className="woocommerce-marketing-channels-card">
|
|
|
|
<CardHeader>
|
|
|
|
<CardHeaderTitle>
|
|
|
|
{ __( 'Channels', 'woocommerce' ) }
|
|
|
|
</CardHeaderTitle>
|
|
|
|
<CardHeaderDescription>
|
|
|
|
{ __(
|
|
|
|
'Start by adding a channel to your store',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</CardHeaderDescription>
|
|
|
|
</CardHeader>
|
2023-01-27 17:12:36 +00:00
|
|
|
{ recommendedChannels.map( ( el, idx ) => {
|
|
|
|
return (
|
|
|
|
<Fragment key={ el.plugin }>
|
|
|
|
<SmartPluginCardBody
|
|
|
|
plugin={ el }
|
|
|
|
onInstalledAndActivated={
|
|
|
|
onInstalledAndActivated
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{ idx < recommendedChannels.length - 1 && (
|
|
|
|
<CardDivider />
|
|
|
|
) }
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
} ) }
|
2022-12-09 16:51:57 +00:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
2022-12-08 15:53:36 +00:00
|
|
|
|
2022-12-09 16:51:57 +00:00
|
|
|
/*
|
2022-12-13 17:13:00 +00:00
|
|
|
* Users have registered channels,
|
|
|
|
* so here we display the registered channels first.
|
2022-12-09 16:51:57 +00:00
|
|
|
* If there are recommended channels,
|
2022-12-13 17:13:00 +00:00
|
|
|
* we display them next in a collapsible list.
|
2022-12-09 16:51:57 +00:00
|
|
|
*/
|
2022-12-08 15:53:36 +00:00
|
|
|
return (
|
2022-12-09 11:50:01 +00:00
|
|
|
<Card className="woocommerce-marketing-channels-card">
|
|
|
|
<CardHeader>
|
|
|
|
<CardHeaderTitle>
|
|
|
|
{ __( 'Channels', 'woocommerce' ) }
|
|
|
|
</CardHeaderTitle>
|
|
|
|
</CardHeader>
|
2022-12-09 16:51:57 +00:00
|
|
|
|
2022-12-13 17:13:00 +00:00
|
|
|
{ /* Registered channels section. */ }
|
2022-12-23 17:14:02 +00:00
|
|
|
{ registeredChannels.map( ( el, idx ) => {
|
2022-12-09 17:37:21 +00:00
|
|
|
return (
|
|
|
|
<Fragment key={ el.slug }>
|
2023-01-20 18:36:39 +00:00
|
|
|
<RegisteredChannelCardBody registeredChannel={ el } />
|
2022-12-23 17:14:02 +00:00
|
|
|
{ idx < registeredChannels.length - 1 && (
|
|
|
|
<CardDivider />
|
|
|
|
) }
|
2022-12-09 17:37:21 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
} ) }
|
2022-12-09 16:51:57 +00:00
|
|
|
|
2022-12-13 17:13:00 +00:00
|
|
|
{ /* Recommended channels section. */ }
|
2022-12-23 17:14:02 +00:00
|
|
|
{ recommendedChannels.length >= 1 && (
|
2023-01-27 17:12:36 +00:00
|
|
|
<div className="woocommerce-marketing-recommended-channels">
|
|
|
|
<CardDivider />
|
|
|
|
<CardBody>
|
|
|
|
<Button
|
|
|
|
variant="link"
|
|
|
|
onClick={ () => setExpanded( ! expanded ) }
|
|
|
|
>
|
|
|
|
{ __( 'Add channels', 'woocommerce' ) }
|
|
|
|
<Icon
|
|
|
|
icon={ expanded ? chevronUp : chevronDown }
|
|
|
|
size={ 24 }
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
</CardBody>
|
|
|
|
{ expanded &&
|
|
|
|
recommendedChannels.map( ( el, idx ) => {
|
|
|
|
return (
|
|
|
|
<Fragment key={ el.plugin }>
|
|
|
|
<SmartPluginCardBody
|
|
|
|
plugin={ el }
|
|
|
|
onInstalledAndActivated={
|
|
|
|
onInstalledAndActivated
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{ idx < recommendedChannels.length - 1 && (
|
|
|
|
<CardDivider />
|
|
|
|
) }
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</div>
|
2022-12-09 16:51:57 +00:00
|
|
|
) }
|
2022-12-08 15:53:36 +00:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|