Show create campaign button in campaigns card when there are campaign types.
This commit is contained in:
parent
81c34086fe
commit
2b477fb93f
|
@ -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 ) }
|
||||
|
|
Loading…
Reference in New Issue