feat: add delete notification button with confirmation in admin notifications
This commit is contained in:
@@ -38,3 +38,23 @@ function sendNotification() {
|
||||
btn.innerHTML = '<i class="fas fa-paper-plane"></i> Send';
|
||||
});
|
||||
}
|
||||
|
||||
function confirmDelete(id, title) {
|
||||
if (!confirm('Delete notification "' + title + '"? This action cannot be undone.')) return;
|
||||
|
||||
const csrf = document.querySelector('meta[name="csrf-token"]')?.content || '';
|
||||
fetch('/admin/notifications/' + id + '/delete', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-Token': csrf,
|
||||
},
|
||||
body: '_csrf_token=' + encodeURIComponent(csrf),
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
showToast(data.success ? 'success' : 'error', data.message);
|
||||
if (data.success) location.reload();
|
||||
})
|
||||
.catch(() => showToast('error', 'Failed to delete notification'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user