/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import {
Button,
Card,
CardHeader,
CardBody,
CardFooter,
Flex,
FlexItem,
FlexBlock,
} from '@wordpress/components';
import { Icon, megaphone, cancelCircleFilled } from '@wordpress/icons';
import {
Pagination,
Table,
TablePlaceholder,
Link,
} from '@woocommerce/components';
import { isWCAdmin } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import {
CardHeaderTitle,
CreateNewCampaignModal,
} from '~/marketing/components';
import { useCampaignTypes, useCampaigns } from '~/marketing/hooks';
import './Campaigns.scss';
const tableCaption = __( 'Campaigns', 'woocommerce' );
const tableHeaders = [
{
key: 'campaign',
label: __( 'Campaign', 'woocommerce' ),
},
{
key: 'cost',
label: __( 'Cost', 'woocommerce' ),
isNumeric: true,
},
{
key: 'sales',
label: __( 'Sales', 'woocommerce' ),
isNumeric: true,
},
];
const perPage = 5;
/**
* Card displaying campaigns in a table.
*
* Pagination will be rendered in the card footer if the total number of campaigns is more than one page.
*
* 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.
*/
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 = () => {
if ( loading ) {
return (