Show create campaign button in campaigns card when there are campaign types.

This commit is contained in:
Gan Eng Chin 2023-06-20 21:05:27 +08:00
parent 81c34086fe
commit 2b477fb93f
No known key found for this signature in database
GPG Key ID: 94D5D972860ADB01
1 changed files with 11 additions and 7 deletions

View File

@ -28,7 +28,7 @@ import {
CardHeaderTitle,
CreateNewCampaignModal,
} from '~/marketing/components';
import { useCampaigns } from '~/marketing/hooks';
import { useCampaignTypes, useCampaigns } from '~/marketing/hooks';
import './Campaigns.scss';
const tableCaption = __( 'Campaigns', 'woocommerce' );
@ -59,6 +59,7 @@ export const Campaigns = () => {
const [ page, setPage ] = useState( 1 );
const [ isModalOpen, setModalOpen ] = useState( false );
const { loading, data, meta } = useCampaigns( page, perPage );
const { data: dataCampaignTypes } = useCampaignTypes();
const total = meta?.total;
const getContent = () => {
@ -158,6 +159,7 @@ export const Campaigns = () => {
);
};
const showCreateCampaignButton = !! dataCampaignTypes?.length;
const showFooter = !! ( total && total > perPage );
return (
@ -166,12 +168,14 @@ export const Campaigns = () => {
<CardHeaderTitle>
{ __( 'Campaigns', 'woocommerce' ) }
</CardHeaderTitle>
{ showCreateCampaignButton && (
<Button
variant="secondary"
onClick={ () => setModalOpen( true ) }
>
{ __( 'Create new campaign', 'woocommerce' ) }
</Button>
) }
{ isModalOpen && (
<CreateNewCampaignModal
onRequestClose={ () => setModalOpen( false ) }