/
index.tsx
98 lines (92 loc) · 2.65 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { dispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { TableCard } from '@woocommerce/components';
import { Hooks } from 'wp-js-hooks';
import { storeName, SubscriberSection } from '../../../store';
import { transformSubscribersToRows } from './rows';
import { Upgrade } from '../orders/upgrade';
const headers = [
{
key: 'last_name',
isSortable: true,
label: __('Subscriber', 'mailpoet'),
},
{
key: 'step',
isSortable: true,
label: __('Automation step', 'mailpoet'),
},
{
key: 'status',
isSortable: true,
label: __('Status', 'mailpoet'),
},
{
key: 'updated_at',
isSortable: true,
label: __('Updated on', 'mailpoet'),
},
];
export function Subscribers(): JSX.Element {
const { subscriberSection } = useSelect((s) => ({
subscriberSection: s(storeName).getSection(
'subscribers',
) as SubscriberSection,
}));
const rows = transformSubscribersToRows(subscriberSection.data);
const beforeTable = Hooks.applyFilters(
'mailpoet_analytics_subscribers_before_table',
<Upgrade />,
) as null | JSX.Element;
return (
<div className="mailpoet-analytics-subscribers">
{beforeTable}
<TableCard
title=""
onQueryChange={(type: string) => (param: unknown) => {
let customQuery = {};
if (type === 'paged') {
customQuery = { page: param };
} else if (type === 'per_page') {
customQuery = {
page: 1,
limit: param,
};
} else if (type === 'sort') {
customQuery = {
page: 1,
order_by: param,
order:
subscriberSection.customQuery.order_by === param &&
subscriberSection.customQuery.order === 'asc'
? 'desc'
: 'asc',
};
}
void dispatch(storeName).updateSection({
...subscriberSection,
customQuery: {
...subscriberSection.customQuery,
...customQuery,
},
});
}}
query={{
paged: subscriberSection.customQuery.page,
orderby: subscriberSection.customQuery.order_by,
order: subscriberSection.customQuery.order,
}}
rows={rows}
headers={headers}
showMenu={false}
rowsPerPage={subscriberSection.customQuery.limit}
totalRows={
subscriberSection.data !== undefined
? subscriberSection.data.results
: 0
}
isLoading={subscriberSection.data?.items === undefined}
/>
</div>
);
}