Merge branch 'feature/34903-multichannel-marketing-frontend/34905-campaigns-card' into feature/34903-multichannel-marketing-frontend/34909-create-campaign-modal

Conflicts:
	plugins/woocommerce-admin/client/marketing/hooks/index.ts
	plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.tsx
	plugins/woocommerce-admin/client/marketing/overview-multichannel/Channels/Channels.tsx
	plugins/woocommerce-admin/client/marketing/overview-multichannel/Channels/RecommendedChannels.tsx
	plugins/woocommerce-admin/client/marketing/overview-multichannel/Channels/useChannels.ts
This commit is contained in:
Gan Eng Chin 2022-12-24 02:07:15 +08:00
commit c89b28157d
No known key found for this signature in database
GPG Key ID: 94D5D972860ADB01
8 changed files with 56 additions and 65 deletions

View File

@ -1,2 +1,3 @@
export { useInstalledPlugins } from './useInstalledPlugins'; export { useInstalledPlugins } from './useInstalledPlugins';
export { useRegisteredChannels } from './useRegisteredChannels';
export { useRecommendedChannels } from './useRecommendedChannels'; export { useRecommendedChannels } from './useRecommendedChannels';

View File

@ -1,3 +1,13 @@
/**
* Internal dependencies
*/
import { InstalledChannel } from '~/marketing/types';
type UseRegisteredChannels = {
loading: boolean;
data: Array< InstalledChannel >;
};
// // TODO: To be removed. This is for testing loading state. // // TODO: To be removed. This is for testing loading state.
// export const useRegisteredChannels = () => { // export const useRegisteredChannels = () => {
// // TODO: call API here to get data. // // TODO: call API here to get data.
@ -17,7 +27,6 @@
// data: [ // data: [
// { // {
// slug: 'google-listings-and-ads', // slug: 'google-listings-and-ads',
// name: 'Google Listings and Ads',
// title: 'Google Listings and Ads', // title: 'Google Listings and Ads',
// description: // description:
// 'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.', // 'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.',
@ -42,7 +51,6 @@
// data: [ // data: [
// { // {
// slug: 'google-listings-and-ads', // slug: 'google-listings-and-ads',
// name: 'Google Listings and Ads',
// title: 'Google Listings and Ads', // title: 'Google Listings and Ads',
// description: // description:
// 'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.', // 'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.',
@ -59,7 +67,7 @@
// }; // };
// TODO: To be removed. This is for testing everything works okay. // TODO: To be removed. This is for testing everything works okay.
export const useRegisteredChannels = () => { export const useRegisteredChannels = (): UseRegisteredChannels => {
// TODO: call API here to get data. // TODO: call API here to get data.
// The following are just dummy data for testing now. // The following are just dummy data for testing now.
return { return {
@ -67,7 +75,6 @@ export const useRegisteredChannels = () => {
data: [ data: [
{ {
slug: 'google-listings-and-ads', slug: 'google-listings-and-ads',
name: 'Google Listings and Ads',
title: 'Google Listings and Ads', title: 'Google Listings and Ads',
description: description:
'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.', 'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.',

View File

@ -4,8 +4,4 @@
align-items: flex-start; align-items: flex-start;
gap: $gap-smallest; gap: $gap-smallest;
} }
.components-button.is-link {
text-decoration: none;
}
} }

View File

@ -3,7 +3,7 @@
*/ */
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
@ -11,46 +11,28 @@ import { Card, CardHeader, CardBody, CardDivider } from '@wordpress/components';
import { import {
CardHeaderTitle, CardHeaderTitle,
CardHeaderDescription, CardHeaderDescription,
CenteredSpinner,
RecommendedChannelsList, RecommendedChannelsList,
} from '~/marketing/components'; } from '~/marketing/components';
import { useChannels } from './useChannels'; import { InstalledChannel, RecommendedChannel } from '~/marketing/types';
import './Channels.scss';
import { InstalledChannelCardBody } from './InstalledChannelCardBody'; import { InstalledChannelCardBody } from './InstalledChannelCardBody';
import { CollapsibleRecommendedChannels } from './CollapsibleRecommendedChannels'; import { RecommendedChannels } from './RecommendedChannels';
import './Channels.scss';
export const Channels = () => { type ChannelsProps = {
const { registeredChannels: Array< InstalledChannel >;
loading, recommendedChannels: Array< RecommendedChannel >;
data: { registeredChannels, recommendedChannels }, };
} = useChannels();
/**
* TODO: we may need to filter the channels against
* `@woocommerce/data` installed plugins.
*/
if ( loading ) {
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 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 ( registeredChannels.length === 0 && recommendedChannels.length > 0 ) { if ( registeredChannels.length === 0 ) {
return ( return (
<Card className="woocommerce-marketing-channels-card"> <Card className="woocommerce-marketing-channels-card">
<CardHeader> <CardHeader>
@ -98,8 +80,8 @@ export const Channels = () => {
} ) } } ) }
{ /* Recommended channels section. */ } { /* Recommended channels section. */ }
{ recommendedChannels.length > 0 && ( { recommendedChannels.length >= 1 && (
<CollapsibleRecommendedChannels <RecommendedChannels
recommendedChannels={ recommendedChannels } recommendedChannels={ recommendedChannels }
/> />
) } ) }

View File

@ -0,0 +1,8 @@
.woocommerce-marketing-recommended-channels {
.components-button.is-link {
font-size: 14px;
font-weight: 600;
line-height: 17px;
text-decoration: none;
}
}

View File

@ -1,20 +0,0 @@
/**
* Internal dependencies
*/
import { useRecommendedChannels } from '~/marketing/hooks';
import { useRegisteredChannels } from './useRegisteredChannels';
export const useChannels = () => {
const { loading: loadingRegistered, data: dataRegistered } =
useRegisteredChannels();
const { loading: loadingRecommended, data: dataRecommended } =
useRecommendedChannels();
return {
loading: loadingRegistered || loadingRecommended,
data: {
registeredChannels: dataRegistered,
recommendedChannels: dataRecommended,
},
};
};

View File

@ -13,20 +13,37 @@ 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">
{ /* TODO: show Campaigns card only when there is at least one registered channel. */ } { dataRegistered.length >= 1 && <Campaigns /> }
<Campaigns /> { ( dataRegistered.length >= 1 || dataRecommended.length >= 1 ) && (
<Channels /> <Channels
registeredChannels={ dataRegistered }
recommendedChannels={ dataRecommended }
/>
) }
<InstalledExtensions /> <InstalledExtensions />
{ shouldShowExtensions && <DiscoverTools /> } { shouldShowExtensions && <DiscoverTools /> }
<LearnMarketing /> <LearnMarketing />