DonorsListTable.tsx
2 years ago
DonorsRowActions.module.scss
3 years ago
DonorsRowActions.tsx
2 years ago
style.scss
3 years ago
DonorsRowActions.tsx
68 lines
| 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 styles from './DonorsRowActions.module.scss'; |
| 8 | import {Interweave} from 'interweave'; |
| 9 | import './style.scss'; |
| 10 | |
| 11 | const donorsApi = new ListTableApi(window.GiveDonors); |
| 12 | |
| 13 | export function DonorsRowActions({item, setUpdateErrors, parameters}) { |
| 14 | const showConfirmModal = useContext(ShowConfirmModalContext); |
| 15 | const {mutate} = useSWRConfig(); |
| 16 | |
| 17 | const fetchAndUpdateErrors = async (parameters, endpoint, id, method) => { |
| 18 | const deleteDonations = document.querySelector('#giveDonorsTableDeleteDonations') as HTMLInputElement; |
| 19 | const response = await donorsApi.fetchWithArgs( |
| 20 | endpoint, |
| 21 | {ids: [id], deleteDonationsAndRecords: deleteDonations.checked}, |
| 22 | method |
| 23 | ); |
| 24 | setUpdateErrors(response); |
| 25 | await mutate(parameters); |
| 26 | return response; |
| 27 | }; |
| 28 | |
| 29 | const deleteDonor = async (selected) => await fetchAndUpdateErrors(parameters, '/delete', item.id, 'DELETE'); |
| 30 | |
| 31 | const confirmDeleteDonor = (selected) => ( |
| 32 | <div> |
| 33 | <p>{__('Really delete the follow donor?', 'give')}</p> |
| 34 | <Interweave attributes={{className: 'donorBulkModalContent'}} content={item?.donorInformation} /> |
| 35 | <br></br> |
| 36 | <input id="giveDonorsTableDeleteDonations" type="checkbox" defaultChecked={true} /> |
| 37 | <label htmlFor="giveDonorsTableDeleteDonations"> |
| 38 | {__('Delete all associated donations and records', 'give')} |
| 39 | </label> |
| 40 | </div> |
| 41 | ); |
| 42 | |
| 43 | const confirmModal = (event) => { |
| 44 | showConfirmModal(__('Delete', 'give'), confirmDeleteDonor, deleteDonor, 'danger'); |
| 45 | }; |
| 46 | |
| 47 | return ( |
| 48 | <div className={styles.container}> |
| 49 | <RowAction |
| 50 | className={styles.action} |
| 51 | href={ |
| 52 | window.GiveDonors.adminUrl + |
| 53 | `edit.php?post_type=give_forms&page=give-donors&view=overview&id=${item.id}` |
| 54 | } |
| 55 | displayText={__('Edit', 'give')} |
| 56 | /> |
| 57 | <RowAction |
| 58 | className={styles.action} |
| 59 | onClick={confirmModal} |
| 60 | actionId={item.id} |
| 61 | displayText={__('Delete', 'give')} |
| 62 | hiddenText={item.name} |
| 63 | highlight |
| 64 | /> |
| 65 | </div> |
| 66 | ); |
| 67 | } |
| 68 |