PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
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 2.30.0 All 255 releases
give / src / Subscriptions / resources / components / SubscriptionsRowActions.tsx

SubscriptionsRowActions.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Subscriptions/resources/components/SubscriptionsRowActions.tsx

76 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {useContext} from 'react';
2 import {ShowConfirmModalContext} from '@givewp/components/ListTable/ListTablePage';
3 import {__, sprintf} from '@wordpress/i18n';
4 import RowAction from '@givewp/components/ListTable/RowAction';
5 import {useSWRConfig} from 'swr';
6 import ListTableApi from '@givewp/components/ListTable/api';
7
8 const subscriptionsApi = new ListTableApi(window.GiveSubscriptions);
9
10 export function SubscriptionsRowActions({item, setUpdateErrors, parameters}) {
11 const showConfirmModal = useContext(ShowConfirmModalContext);
12 const {mutate} = useSWRConfig();
13
14 const fetchAndUpdateErrors = async (parameters, endpoint, id, method) => {
15 const response = await subscriptionsApi.fetchWithArgs(endpoint, {ids: [id]}, method);
16 setUpdateErrors(response);
17 await mutate(parameters);
18 return response;
19 };
20
21 const deleteItem = async () => await fetchAndUpdateErrors(parameters, '/delete', item.id, 'DELETE');
22 const trashItem = async () => await fetchAndUpdateErrors(parameters, '/trash', item.id, 'DELETE');
23 const restoreItem = async () => await fetchAndUpdateErrors(parameters, '/untrash', item.id, 'POST');
24
25 const confirmDelete = () => <p>{sprintf(__('Really delete subscription #%d?', 'give'), item.id)}</p>;
26 const confirmTrash = () => <p>{sprintf(__('Trash the following subscription #%d?', 'give'), item.id)}</p>;
27 const confirmRestore = () => <p>{sprintf(__('Restore the following subscription #%d?', 'give'), item.id)}</p>;
28
29 const confirmDeleteModal = () => {
30 showConfirmModal(__('Delete', 'give'), confirmDelete, deleteItem, 'danger');
31 };
32
33 const confirmTrashModal = () => {
34 showConfirmModal(__('Trash', 'give'), confirmTrash, trashItem, 'warning');
35 };
36
37 const confirmRestoreModal = () => {
38 showConfirmModal(__('Restore', 'give'), confirmRestore, restoreItem, 'normal');
39 };
40
41 return (
42 <>
43 {parameters?.status?.includes('trashed') ? (
44 <>
45 <RowAction
46 onClick={confirmRestoreModal}
47 actionId={item.id}
48 displayText={__('Restore', 'give')}
49 />
50 <RowAction
51 onClick={confirmDeleteModal}
52 actionId={item.id}
53 displayText={__('Delete', 'give')}
54 hiddenText={item.name}
55 highlight
56 />
57 </>
58 ) : (
59 <>
60 <RowAction
61 href={`edit.php?post_type=give_forms&page=give-subscriptions&id=${item.id}`}
62 displayText={__('Edit', 'give')}
63 />
64 <RowAction
65 onClick={confirmTrashModal}
66 actionId={item.id}
67 displayText={__('Trash', 'give')}
68 hiddenText={item.name}
69 highlight
70 />
71 </>
72 )}
73 </>
74 );
75 }
76