Load campaign types in overview and refetch after installeing a channel.
This commit is contained in:
parent
8b6aad4138
commit
6446053784
|
@ -25,7 +25,6 @@ import {
|
|||
* Internal dependencies
|
||||
*/
|
||||
import { CardHeaderTitle } from '~/marketing/components';
|
||||
import { useCampaignTypes } from '~/marketing/hooks';
|
||||
import { useCampaigns } from './useCampaigns';
|
||||
import { CreateNewCampaignModal } from './CreateNewCampaignModal';
|
||||
import './Campaigns.scss';
|
||||
|
@ -53,24 +52,15 @@ const perPage = 5;
|
|||
* If there are no campaigns, there will be no table but an info message instead.
|
||||
*
|
||||
* If there is an error, there will be no table but an error message instead.
|
||||
*
|
||||
* The new campaign types data will also be loaded,
|
||||
* so that when users click on the "Create new campaign" button in the card header,
|
||||
* there will be no loading necessary in the modal.
|
||||
*/
|
||||
export const Campaigns = () => {
|
||||
const [ page, setPage ] = useState( 1 );
|
||||
const [ isModalOpen, setModalOpen ] = useState( false );
|
||||
const {
|
||||
loading: loadingCampaigns,
|
||||
data,
|
||||
meta,
|
||||
} = useCampaigns( page, perPage );
|
||||
const { loading: loadingNewCampaignTypes } = useCampaignTypes();
|
||||
const { loading, data, meta } = useCampaigns( page, perPage );
|
||||
const total = meta?.total;
|
||||
|
||||
const getContent = () => {
|
||||
if ( loadingNewCampaignTypes || loadingCampaigns ) {
|
||||
if ( loading ) {
|
||||
return (
|
||||
<TablePlaceholder
|
||||
caption={ tableCaption }
|
||||
|
|
|
@ -12,6 +12,7 @@ import { CenteredSpinner } from '~/marketing/components';
|
|||
import {
|
||||
useRegisteredChannels,
|
||||
useRecommendedChannels,
|
||||
useCampaignTypes,
|
||||
} from '~/marketing/hooks';
|
||||
import { getAdminSetting } from '~/utils/admin-settings';
|
||||
import { Campaigns } from './Campaigns';
|
||||
|
@ -22,26 +23,37 @@ import { LearnMarketing } from './LearnMarketing';
|
|||
import './MarketingOverviewMultichannel.scss';
|
||||
|
||||
export const MarketingOverviewMultichannel: React.FC = () => {
|
||||
const {
|
||||
loading: loadingCampaignTypes,
|
||||
data: dataCampaignTypes,
|
||||
refetch: refetchCampaignTypes,
|
||||
} = useCampaignTypes();
|
||||
const {
|
||||
loading: loadingRegistered,
|
||||
data: dataRegistered,
|
||||
refetch,
|
||||
refetch: refetchRegisteredChannels,
|
||||
} = useRegisteredChannels();
|
||||
const { loading: loadingRecommended, data: dataRecommended } =
|
||||
useRecommendedChannels();
|
||||
const { currentUserCan } = useUser();
|
||||
|
||||
const shouldShowExtensions =
|
||||
getAdminSetting( 'allowMarketplaceSuggestions', false ) &&
|
||||
currentUserCan( 'install_plugins' );
|
||||
|
||||
if (
|
||||
( loadingCampaignTypes && ! dataCampaignTypes ) ||
|
||||
( loadingRegistered && ! dataRegistered ) ||
|
||||
( loadingRecommended && ! dataRecommended )
|
||||
) {
|
||||
return <CenteredSpinner />;
|
||||
}
|
||||
|
||||
const shouldShowExtensions =
|
||||
getAdminSetting( 'allowMarketplaceSuggestions', false ) &&
|
||||
currentUserCan( 'install_plugins' );
|
||||
|
||||
const refetch = () => {
|
||||
refetchCampaignTypes();
|
||||
refetchRegisteredChannels();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="woocommerce-marketing-overview-multichannel">
|
||||
{ dataRegistered?.length && <Campaigns /> }
|
||||
|
|
Loading…
Reference in New Issue