PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.0
GiveWP – Donation Plugin and Fundraising Platform v4.16.0
4.18.0.1 4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 All 258 releases
give / src / DonorDashboards / resources / js / app / components / subscription-table / index.js

index.js in GiveWP – Donation Plugin and Fundraising Platform 4.16.0, at src/DonorDashboards/resources/js/app/components/subscription-table/index.js

84 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {Fragment, useState} from 'react';
2 import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
3 import {__} from '@wordpress/i18n';
4
5 import Table from '../table';
6 import SubscriptionRow from '../subscription-row';
7
8 import './style.scss';
9
10 const SubscriptionTable = ({subscriptions, perPage}) => {
11 const [page, setPage] = useState(1);
12
13 const getStartIndex = () => {
14 return (page - 1) * perPage;
15 };
16
17 const getEndIndex = () => {
18 return start + perPage <= subscriptionsArray.length ? start + perPage : subscriptionsArray.length;
19 };
20
21 const getSubscriptionRows = () => {
22 return subscriptionsArray.reduce((rows, subscription, index) => {
23 if (index >= start && index < end) {
24 rows.push(<SubscriptionRow subscription={subscription} key={index} />);
25 }
26 return rows;
27 }, []);
28 };
29
30 let subscriptionRows = [];
31 const subscriptionsArray = [];
32 let start = 0;
33 let end = perPage;
34 let lastPage = 1;
35
36 if (subscriptions) {
37 Object.entries(subscriptions).forEach((subscription) => {
38 subscriptionsArray[subscription[0]] = subscription[1];
39 });
40 start = getStartIndex();
41 end = getEndIndex();
42 lastPage = Math.ceil(subscriptionsArray.length / perPage) - 1;
43 subscriptionRows = getSubscriptionRows();
44 }
45
46 return (
47 <Table
48 header={
49 <Fragment>
50 <div className="give-donor-dashboard-table__column">{__('Subscription', 'give')}</div>
51 <div className="give-donor-dashboard-table__column">{__('Status', 'give')}</div>
52 <div className="give-donor-dashboard-table__column">{__('Next Renewal', 'give')}</div>
53 <div className="give-donor-dashboard-table__column">{__('Progress', 'give')}</div>
54 </Fragment>
55 }
56 rows={<Fragment>{subscriptionRows}</Fragment>}
57 footer={
58 <Fragment>
59 <div className="give-donor-dashboard-table__footer-text">
60 {subscriptions &&
61 `${__('Showing', 'give')} ${start + 1} - ${end} ${__('of', 'give')} ${
62 subscriptionsArray.length
63 } ${__('Subscriptions', 'give')}`}
64 </div>
65 <div className="give-donor-dashboard-table__footer-nav">
66 {page - 1 >= 1 && (
67 <a onClick={() => setPage(page - 1)}>
68 <FontAwesomeIcon icon="chevron-left" />
69 </a>
70 )}
71 {page <= lastPage && (
72 <a onClick={() => setPage(page + 1)}>
73 <FontAwesomeIcon icon="chevron-right" />
74 </a>
75 )}
76 </div>
77 </Fragment>
78 }
79 />
80 );
81 };
82
83 export default SubscriptionTable;
84