2022-12-15 17:13:32 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-12-18 12:37:25 +00:00
|
|
|
import { useState } from '@wordpress/element';
|
2022-12-18 12:08:21 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Card,
|
|
|
|
CardHeader,
|
|
|
|
CardBody,
|
2022-12-18 12:37:25 +00:00
|
|
|
CardFooter,
|
2022-12-18 12:08:21 +00:00
|
|
|
Flex,
|
|
|
|
FlexItem,
|
|
|
|
FlexBlock,
|
|
|
|
} from '@wordpress/components';
|
2022-12-15 17:13:32 +00:00
|
|
|
import { Icon, megaphone } from '@wordpress/icons';
|
2022-12-18 12:37:25 +00:00
|
|
|
import { Pagination, Table } from '@woocommerce/components';
|
2022-12-15 17:13:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-12-17 13:08:14 +00:00
|
|
|
import { CardHeaderTitle, CenteredSpinner } from '~/marketing/components';
|
|
|
|
import { useCampaigns } from './useCampaigns';
|
2022-12-15 17:13:32 +00:00
|
|
|
import './Campaigns.scss';
|
|
|
|
|
|
|
|
export const Campaigns = () => {
|
2022-12-18 12:37:25 +00:00
|
|
|
const [ page, setPage ] = useState( 1 );
|
2022-12-17 13:08:14 +00:00
|
|
|
const { loading, data } = useCampaigns();
|
|
|
|
|
|
|
|
if ( loading ) {
|
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardHeader>
|
|
|
|
<CardHeaderTitle>
|
|
|
|
{ __( 'Campaigns', 'woocommerce' ) }
|
|
|
|
</CardHeaderTitle>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody>
|
|
|
|
<CenteredSpinner />
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data.length === 0 ) {
|
|
|
|
return (
|
|
|
|
<Card className="woocommerce-marketing-campaigns-card">
|
|
|
|
<CardHeader>
|
|
|
|
<CardHeaderTitle>
|
|
|
|
{ __( 'Campaigns', 'woocommerce' ) }
|
|
|
|
</CardHeaderTitle>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody className="woocommerce-marketing-campaigns-card-body-empty-content">
|
|
|
|
<Icon icon={ megaphone } size={ 32 } />
|
|
|
|
<div className="woocommerce-marketing-campaigns-card-body-empty-content-title">
|
|
|
|
{ __(
|
|
|
|
'Advertise with marketing campaigns',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{ __(
|
|
|
|
'Easily create and manage marketing campaigns without leaving WooCommerce.',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-18 12:37:25 +00:00
|
|
|
const perPage = 5;
|
|
|
|
const total = data.length;
|
|
|
|
const start = ( page - 1 ) * perPage;
|
|
|
|
const pagedData = data.slice( start, start + perPage );
|
|
|
|
|
2022-12-18 11:34:16 +00:00
|
|
|
return (
|
|
|
|
<Card className="woocommerce-marketing-campaigns-card">
|
|
|
|
<CardHeader>
|
|
|
|
<CardHeaderTitle>
|
|
|
|
{ __( 'Campaigns', 'woocommerce' ) }
|
|
|
|
</CardHeaderTitle>
|
|
|
|
</CardHeader>
|
|
|
|
<Table
|
2022-12-18 12:37:25 +00:00
|
|
|
caption={ __( 'Campaigns', 'woocommerce' ) }
|
2022-12-18 11:34:16 +00:00
|
|
|
headers={ [
|
|
|
|
{
|
|
|
|
key: 'campaign',
|
|
|
|
label: __( 'Campaign', 'woocommerce' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'cost',
|
|
|
|
label: __( 'Cost', 'woocommerce' ),
|
2022-12-18 12:38:07 +00:00
|
|
|
isNumeric: true,
|
2022-12-18 11:34:16 +00:00
|
|
|
},
|
|
|
|
] }
|
2022-12-18 12:37:25 +00:00
|
|
|
ids={ pagedData.map( ( el ) => el.id ) }
|
|
|
|
rows={ pagedData.map( ( el ) => {
|
2022-12-18 11:34:16 +00:00
|
|
|
return [
|
2022-12-18 12:08:21 +00:00
|
|
|
{
|
|
|
|
display: (
|
|
|
|
<Flex gap={ 4 }>
|
|
|
|
<FlexItem className="woocommerce-marketing-campaign-logo">
|
|
|
|
<img
|
|
|
|
src={ el.icon }
|
|
|
|
alt={ el.channelName }
|
|
|
|
width="16"
|
|
|
|
height="16"
|
|
|
|
/>
|
|
|
|
</FlexItem>
|
|
|
|
<FlexBlock>
|
|
|
|
<Flex direction="column" gap={ 1 }>
|
|
|
|
<FlexItem className="woocommerce-marketing-campaign-title">
|
|
|
|
<a href={ el.manageUrl }>
|
|
|
|
{ el.title }
|
|
|
|
</a>
|
|
|
|
</FlexItem>
|
|
|
|
<FlexItem className="woocommerce-marketing-campaign-description">
|
|
|
|
{ el.description }
|
|
|
|
</FlexItem>
|
|
|
|
</Flex>
|
|
|
|
</FlexBlock>
|
|
|
|
</Flex>
|
|
|
|
),
|
|
|
|
},
|
2022-12-18 11:34:16 +00:00
|
|
|
{ display: el.cost },
|
|
|
|
];
|
|
|
|
} ) }
|
|
|
|
/>
|
2022-12-18 12:37:25 +00:00
|
|
|
<CardFooter className="woocommerce-marketing-campaigns-card-footer">
|
|
|
|
<Pagination
|
|
|
|
showPerPagePicker={ false }
|
|
|
|
perPage={ 5 }
|
|
|
|
page={ page }
|
|
|
|
total={ total }
|
|
|
|
onPageChange={ ( newPage: number ) => {
|
|
|
|
setPage( newPage );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
</CardFooter>
|
2022-12-18 11:34:16 +00:00
|
|
|
</Card>
|
|
|
|
);
|
2022-12-15 17:13:32 +00:00
|
|
|
};
|