/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import {
Card,
CardHeader,
CardBody,
CardFooter,
Flex,
FlexItem,
FlexBlock,
} from '@wordpress/components';
import { Icon, megaphone, cancelCircleFilled } from '@wordpress/icons';
import { Pagination, Table, Link } from '@woocommerce/components';
/**
* Internal dependencies
*/
import { CardHeaderTitle, CenteredSpinner } from '~/marketing/components';
import { useCampaigns } from './useCampaigns';
import './Campaigns.scss';
export const Campaigns = () => {
const [ page, setPage ] = useState( 1 );
const { loading, data } = useCampaigns();
const getContent = () => {
if ( loading ) {
return (
);
}
if ( ! data ) {
return (
{ __( 'An unexpected error occurred.', 'woocommerce' ) }
{ __(
'Please try again later. Check the logs if the problem persists. ',
'woocommerce'
) }
);
}
if ( data.length === 0 ) {
return (
{ __(
'Advertise with marketing campaigns',
'woocommerce'
) }
{ __(
'Easily create and manage marketing campaigns without leaving WooCommerce.',
'woocommerce'
) }
);
}
const perPage = 5;
const total = data.length;
const start = ( page - 1 ) * perPage;
const pagedData = data.slice( start, start + perPage );
return (
<>
{
return [
{
display: (
{ el.title }
{ el.description && (
{ el.description }
) }
),
},
{ display: el.cost },
];
} ) }
/>
{ total > perPage && (
{
setPage( newPage );
} }
/>
) }
>
);
};
return (
{ __( 'Campaigns', 'woocommerce' ) }
{ getContent() }
);
};