fix: replace confirm() with proper delete confirmation modal

This commit is contained in:
2026-06-14 10:07:21 -04:00
parent a25ebdcb75
commit 01f1215cef
2 changed files with 52 additions and 7 deletions

View File

@@ -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 = '<i class="fas fa-spinner fa-spin"></i> 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) {