DonationRowActions.tsx
10 months ago
DonationsListTable.tsx
1 year ago
ListTable.module.scss
3 years ago
DonationRowActions.tsx
45 lines
| 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 { store as coreDataStore } from '@wordpress/core-data'; |
| 6 | import { useDispatch } from '@wordpress/data'; |
| 7 | |
| 8 | /** |
| 9 | * @since 4.6.0 Soft delete donations with Donation v3 API. |
| 10 | */ |
| 11 | export const DonationRowActions = ({item, removeRow, setUpdateErrors, parameters}) => { |
| 12 | const showConfirmModal = useContext(ShowConfirmModalContext); |
| 13 | const { deleteEntityRecord } = useDispatch( coreDataStore ); |
| 14 | |
| 15 | const deleteItem = async (selected) => { |
| 16 | await deleteEntityRecord('givewp', 'donation', item.id, {force: false}); |
| 17 | window.location.reload(); |
| 18 | }; |
| 19 | |
| 20 | const confirmDelete = (selected) => <p>{sprintf(__('Are you sure you want to move donation #%d to the trash?', 'give'), item.id)}</p>; |
| 21 | |
| 22 | const confirmModal = (event) => { |
| 23 | showConfirmModal(__('Move donation to trash', 'give'), confirmDelete, deleteItem, 'danger', __('Trash Donation', 'give')); |
| 24 | }; |
| 25 | |
| 26 | return ( |
| 27 | <> |
| 28 | <RowAction |
| 29 | href={ |
| 30 | window.GiveDonations.adminUrl + |
| 31 | `edit.php?post_type=give_forms&page=give-payment-history&id=${item.id}` |
| 32 | } |
| 33 | displayText={__('Edit', 'give')} |
| 34 | /> |
| 35 | <RowAction |
| 36 | onClick={confirmModal} |
| 37 | actionId={item.id} |
| 38 | displayText={__('Trash', 'give')} |
| 39 | hiddenText={item.name} |
| 40 | highlight |
| 41 | /> |
| 42 | </> |
| 43 | ); |
| 44 | }; |
| 45 |