2022-09-14 07:43:30 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-03-07 18:06:06 +00:00
|
|
|
import { useRef } from '@wordpress/element';
|
2022-09-14 07:43:30 +00:00
|
|
|
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 {
|
2022-12-27 14:01:46 +00:00
|
|
|
useIntroductionBanner,
|
2023-03-19 15:30:21 +00:00
|
|
|
useCampaigns,
|
2022-12-23 17:14:02 +00:00
|
|
|
useRegisteredChannels,
|
|
|
|
useRecommendedChannels,
|
2023-03-09 15:46:54 +00:00
|
|
|
useCampaignTypes,
|
2023-03-22 10:35:06 +00:00
|
|
|
useInstalledPluginsWithoutChannels,
|
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';
|
2023-03-06 16:46:38 +00:00
|
|
|
import { IntroductionBanner } from './IntroductionBanner';
|
2022-12-15 17:13:32 +00:00
|
|
|
import { Campaigns } from './Campaigns';
|
2023-03-19 17:00:19 +00:00
|
|
|
import { Channels, ChannelsRef } 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 = () => {
|
2022-12-27 14:01:46 +00:00
|
|
|
const {
|
|
|
|
loading: loadingIntroductionBanner,
|
|
|
|
isIntroductionBannerDismissed,
|
|
|
|
dismissIntroductionBanner,
|
|
|
|
} = useIntroductionBanner();
|
2023-03-19 15:30:21 +00:00
|
|
|
const { loading: loadingCampaigns, meta: metaCampaigns } = useCampaigns();
|
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();
|
2023-03-22 10:35:06 +00:00
|
|
|
const { loadInstalledPluginsAfterActivation } =
|
|
|
|
useInstalledPluginsWithoutChannels();
|
2022-09-14 07:43:30 +00:00
|
|
|
const { currentUserCan } = useUser();
|
2023-03-19 17:00:19 +00:00
|
|
|
const channelsRef = useRef< ChannelsRef >( null );
|
2022-09-14 07:43:30 +00:00
|
|
|
|
2023-01-19 17:02:41 +00:00
|
|
|
if (
|
2022-12-27 14:01:46 +00:00
|
|
|
loadingIntroductionBanner ||
|
2023-03-19 15:30:21 +00:00
|
|
|
( loadingCampaigns && metaCampaigns?.total === undefined ) ||
|
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-27 13:55:42 +00:00
|
|
|
const showCampaigns = !! (
|
2023-03-19 15:30:21 +00:00
|
|
|
dataRegistered?.length &&
|
2023-03-20 09:23:20 +00:00
|
|
|
( isIntroductionBannerDismissed || metaCampaigns?.total )
|
|
|
|
);
|
2023-03-19 15:30:21 +00:00
|
|
|
|
2023-03-27 13:55:42 +00:00
|
|
|
const showChannels = !! (
|
|
|
|
dataRegistered &&
|
|
|
|
dataRecommended &&
|
|
|
|
( dataRegistered.length || dataRecommended.length )
|
|
|
|
);
|
|
|
|
|
|
|
|
const showExtensions = !! (
|
2023-03-09 15:46:54 +00:00
|
|
|
getAdminSetting( 'allowMarketplaceSuggestions', false ) &&
|
2023-03-27 13:55:42 +00:00
|
|
|
currentUserCan( 'install_plugins' )
|
|
|
|
);
|
2023-03-09 15:46:54 +00:00
|
|
|
|
2023-03-17 16:47:54 +00:00
|
|
|
const onInstalledAndActivated = ( pluginSlug: string ) => {
|
2023-03-09 15:46:54 +00:00
|
|
|
refetchCampaignTypes();
|
|
|
|
refetchRegisteredChannels();
|
2023-03-17 16:47:54 +00:00
|
|
|
loadInstalledPluginsAfterActivation( pluginSlug );
|
2023-03-09 15:46:54 +00:00
|
|
|
};
|
|
|
|
|
2022-09-14 07:43:30 +00:00
|
|
|
return (
|
|
|
|
<div className="woocommerce-marketing-overview-multichannel">
|
2022-12-27 14:01:46 +00:00
|
|
|
{ ! isIntroductionBannerDismissed && (
|
|
|
|
<IntroductionBanner
|
2023-03-19 13:10:22 +00:00
|
|
|
onDismissClick={ dismissIntroductionBanner }
|
|
|
|
onAddChannelsClick={ () => {
|
2023-03-19 17:00:19 +00:00
|
|
|
channelsRef.current?.scrollIntoAddChannels();
|
2023-03-07 18:06:06 +00:00
|
|
|
} }
|
2022-12-27 14:01:46 +00:00
|
|
|
/>
|
|
|
|
) }
|
2023-03-27 13:55:42 +00:00
|
|
|
{ showCampaigns && <Campaigns /> }
|
|
|
|
{ showChannels && (
|
|
|
|
<Channels
|
|
|
|
ref={ channelsRef }
|
|
|
|
registeredChannels={ dataRegistered }
|
|
|
|
recommendedChannels={ dataRecommended }
|
|
|
|
onInstalledAndActivated={ onInstalledAndActivated }
|
|
|
|
/>
|
|
|
|
) }
|
2022-09-14 07:43:30 +00:00
|
|
|
<InstalledExtensions />
|
2023-03-27 13:55:42 +00:00
|
|
|
{ showExtensions && <DiscoverTools /> }
|
2022-09-14 07:43:30 +00:00
|
|
|
<LearnMarketing />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|