fix: replace confirm() with proper delete confirmation modal
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user