delete-group.js
3 months ago
edit-group.js
1 month ago
form-submission.js
3 months ago
forms.css
3 months ago
icons.css
3 months ago
listShowMore.js
3 months ago
listing.css
3 months ago
listing.js
3 months ago
sort-ads.js
3 months ago
table.css
3 months ago
delete-group.js
48 lines
| 1 | import apiFetch from '@wordpress/api-fetch'; |
| 2 | |
| 3 | import { groups } from '@advancedAds/i18n'; |
| 4 | import { notifications } from '@advancedAds'; |
| 5 | |
| 6 | export function deleteGroup() { |
| 7 | document.addEventListener( 'click', function ( event ) { |
| 8 | const target = event.target; |
| 9 | |
| 10 | if ( ! target.matches( '.delete-tag' ) ) { |
| 11 | return; |
| 12 | } |
| 13 | |
| 14 | event.preventDefault(); |
| 15 | |
| 16 | const groupName = target |
| 17 | .closest( 'div' ) |
| 18 | .parentElement.querySelector( '.advads-table-name a' ).textContent; |
| 19 | |
| 20 | if ( |
| 21 | // eslint-disable-next-line no-alert |
| 22 | ! window.confirm( |
| 23 | groups.confirmation.replace( '%s', groupName.trim() ) |
| 24 | ) |
| 25 | ) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | const href = target.getAttribute( 'href' ); |
| 30 | const queryVars = new URLSearchParams( href ); |
| 31 | const tr = target.closest( 'tr' ); |
| 32 | |
| 33 | apiFetch( { |
| 34 | path: '/advanced-ads/v1/group', |
| 35 | method: 'DELETE', |
| 36 | data: { |
| 37 | id: queryVars.get( 'group_id' ), |
| 38 | nonce: queryVars.get( '_wpnonce' ), |
| 39 | }, |
| 40 | } ).then( function ( response ) { |
| 41 | if ( response.done ) { |
| 42 | tr.remove(); |
| 43 | notifications.addSuccess( groups.deleted ); |
| 44 | } |
| 45 | } ); |
| 46 | } ); |
| 47 | } |
| 48 |