2022-09-14 07:43:30 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useUser } from '@woocommerce/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import '~/marketing/data';
|
2023-01-17 18:04:42 +00:00
|
|
|
import '~/marketing/data-multichannel';
|
2023-01-31 15:39:02 +00:00
|
|
|
import { CenteredSpinner } from '~/marketing/components';
|
2022-12-23 17:14:02 +00:00
|
|
|
import {
|
|
|
|
useRegisteredChannels,
|
|
|
|
useRecommendedChannels,
|
2023-03-09 15:46:54 +00:00
|
|
|
useCampaignTypes,
|
2022-12-23 17:14:02 +00:00
|
|
|
} from '~/marketing/hooks';
|
2022-09-14 07:43:30 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2022-12-15 17:13:32 +00:00
|
|
|
import { Campaigns } from './Campaigns';
|
2022-12-08 15:53:36 +00:00
|
|
|
import { Channels } from './Channels';
|
2022-09-14 07:43:30 +00:00
|
|
|
import { InstalledExtensions } from './InstalledExtensions';
|
|
|
|
import { DiscoverTools } from './DiscoverTools';
|
|
|
|
import { LearnMarketing } from './LearnMarketing';
|
|
|
|
import './MarketingOverviewMultichannel.scss';
|
|
|
|
|
|
|
|
export const MarketingOverviewMultichannel: React.FC = () => {
|
2023-03-09 15:46:54 +00:00
|
|
|
const {
|
|
|
|
loading: loadingCampaignTypes,
|
|
|
|
data: dataCampaignTypes,
|
|
|
|
refetch: refetchCampaignTypes,
|
|
|
|
} = useCampaignTypes();
|
2023-01-19 17:02:41 +00:00
|
|
|
const {
|
|
|
|
loading: loadingRegistered,
|
|
|
|
data: dataRegistered,
|
2023-03-09 15:46:54 +00:00
|
|
|
refetch: refetchRegisteredChannels,
|
2023-01-19 17:02:41 +00:00
|
|
|
} = useRegisteredChannels();
|
2022-12-23 17:14:02 +00:00
|
|
|
const { loading: loadingRecommended, data: dataRecommended } =
|
|
|
|
useRecommendedChannels();
|
2022-09-14 07:43:30 +00:00
|
|
|
const { currentUserCan } = useUser();
|
|
|
|
|
2023-01-19 17:02:41 +00:00
|
|
|
if (
|
2023-03-09 15:46:54 +00:00
|
|
|
( loadingCampaignTypes && ! dataCampaignTypes ) ||
|
2023-01-19 17:02:41 +00:00
|
|
|
( loadingRegistered && ! dataRegistered ) ||
|
|
|
|
( loadingRecommended && ! dataRecommended )
|
|
|
|
) {
|
2022-12-23 17:14:02 +00:00
|
|
|
return <CenteredSpinner />;
|
|
|
|
}
|
|
|
|
|
2023-03-09 15:46:54 +00:00
|
|
|
const shouldShowExtensions =
|
|
|
|
getAdminSetting( 'allowMarketplaceSuggestions', false ) &&
|
|
|
|
currentUserCan( 'install_plugins' );
|
|
|
|
|
|
|
|
const refetch = () => {
|
|
|
|
refetchCampaignTypes();
|
|
|
|
refetchRegisteredChannels();
|
|
|
|
};
|
|
|
|
|
2022-09-14 07:43:30 +00:00
|
|
|
return (
|
|
|
|
<div className="woocommerce-marketing-overview-multichannel">
|
2023-03-07 13:06:25 +00:00
|
|
|
{ !! dataRegistered?.length && <Campaigns /> }
|
2023-01-19 17:02:41 +00:00
|
|
|
{ dataRegistered &&
|
|
|
|
dataRecommended &&
|
2023-03-07 13:06:25 +00:00
|
|
|
!! ( dataRegistered.length || dataRecommended.length ) && (
|
2023-01-19 17:02:41 +00:00
|
|
|
<Channels
|
|
|
|
registeredChannels={ dataRegistered }
|
|
|
|
recommendedChannels={ dataRecommended }
|
|
|
|
onInstalledAndActivated={ refetch }
|
|
|
|
/>
|
|
|
|
) }
|
2022-09-14 07:43:30 +00:00
|
|
|
<InstalledExtensions />
|
|
|
|
{ shouldShowExtensions && <DiscoverTools /> }
|
|
|
|
<LearnMarketing />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|