diff --git a/public/assets/js/admin-notifications.js b/public/assets/js/admin-notifications.js index 4020e0a..ce2d492 100644 --- a/public/assets/js/admin-notifications.js +++ b/public/assets/js/admin-notifications.js @@ -39,11 +39,27 @@ function sendNotification() { }); } -function confirmDelete(id, title) { - if (!confirm('Delete notification "' + title + '"? This action cannot be undone.')) return; +let deleteId = null; + +function showDeleteModal(id, title) { + deleteId = id; + document.getElementById('deleteModalTitle').textContent = '"' + title + '"'; + document.getElementById('deleteModal').style.display = 'flex'; +} + +function closeDeleteModal() { + deleteId = null; + document.getElementById('deleteModal').style.display = 'none'; +} + +function executeDelete() { + if (!deleteId) return; + const btn = document.getElementById('deleteConfirmBtn'); + btn.disabled = true; + btn.innerHTML = ' Deleting...'; const csrf = document.querySelector('meta[name="csrf-token"]')?.content || ''; - fetch('/admin/notifications/' + id + '/delete', { + fetch('/admin/notifications/' + deleteId + '/delete', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', @@ -54,9 +70,13 @@ function confirmDelete(id, title) { .then(r => r.json()) .then(data => { showToast(data.success ? 'success' : 'error', data.message); + closeDeleteModal(); if (data.success) location.reload(); }) - .catch(() => showToast('error', 'Failed to delete notification')); + .catch(() => { + showToast('error', 'Failed to delete notification'); + closeDeleteModal(); + }); } function confirmResend(id) { diff --git a/views/admin/notifications.php b/views/admin/notifications.php index 88d5dcd..61becab 100644 --- a/views/admin/notifications.php +++ b/views/admin/notifications.php @@ -73,9 +73,9 @@ $data = $notifications['data'] ?? []; style="color:var(--info)"> - @@ -154,4 +154,29 @@ $data = $notifications['data'] ?? []; + + +