PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.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 2.3.1 2.3.2 All 256 releases
give / src / Donors / resources / components / DonorsRowActions.tsx

DonorsRowActions.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/Donors/resources/components/DonorsRowActions.tsx

65 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {__} from '@wordpress/i18n';
2 import {useSWRConfig} from 'swr';
3 import RowAction from '@givewp/components/ListTable/RowAction';
4 import ListTableApi from '@givewp/components/ListTable/api';
5 import {useContext} from 'react';
6 import {ShowConfirmModalContext} from '@givewp/components/ListTable/ListTablePage';
7 import {Interweave} from 'interweave';
8 import './style.scss';
9
10 const donorsApi = new ListTableApi(window.GiveDonors);
11
12 export function DonorsRowActions({item, setUpdateErrors, parameters}) {
13 const showConfirmModal = useContext(ShowConfirmModalContext);
14 const {mutate} = useSWRConfig();
15
16 const fetchAndUpdateErrors = async (parameters, endpoint, id, method) => {
17 const deleteDonations = document.querySelector('#giveDonorsTableDeleteDonations') as HTMLInputElement;
18 const response = await donorsApi.fetchWithArgs(
19 endpoint,
20 {ids: [id], deleteDonationsAndRecords: deleteDonations.checked},
21 method
22 );
23 setUpdateErrors(response);
24 await mutate(parameters);
25 return response;
26 };
27
28 const deleteDonor = async (selected) => await fetchAndUpdateErrors(parameters, '/delete', item.id, 'DELETE');
29
30 const confirmDeleteDonor = (selected) => (
31 <div>
32 <p>{__('Really delete the follow donor?', 'give')}</p>
33 <Interweave attributes={{className: 'donorBulkModalContent'}} content={item?.donorInformation} />
34 <br></br>
35 <input id="giveDonorsTableDeleteDonations" type="checkbox" defaultChecked={true} />
36 <label htmlFor="giveDonorsTableDeleteDonations">
37 {__('Delete all associated donations and records', 'give')}
38 </label>
39 </div>
40 );
41
42 const confirmModal = (event) => {
43 showConfirmModal(__('Delete', 'give'), confirmDeleteDonor, deleteDonor, 'danger');
44 };
45
46 return (
47 <>
48 <RowAction
49 href={
50 window.GiveDonors.adminUrl +
51 `edit.php?post_type=give_forms&page=give-donors&view=overview&id=${item.id}`
52 }
53 displayText={__('Edit', 'give')}
54 />
55 <RowAction
56 onClick={confirmModal}
57 actionId={item.id}
58 displayText={__('Delete', 'give')}
59 hiddenText={item.name}
60 highlight
61 />
62 </>
63 );
64 }
65