Updates to sending user details

This commit is contained in:
2025-08-03 13:26:20 -06:00
parent 6b4732db65
commit 86685a13a6
22 changed files with 1669 additions and 156 deletions

View File

@@ -346,7 +346,7 @@ function setupEventListeners() {
}
// User form submission
const userForm = document.getElementById('user-form');
const userForm = document.getElementById('create-user-form');
if (userForm) {
userForm.addEventListener('submit', createUser);
}
@@ -1269,6 +1269,9 @@ function displayUsers(users) {
<td data-label="Created">${formattedDate}</td>
<td data-label="Actions">
<div class="user-actions">
<button class="btn btn-secondary send-login-btn" data-user-id="${userId}" data-user-email="${escapeHtml(user.email || user.Email)}">
Send Login Details
</button>
<button class="btn btn-danger delete-user-btn" data-user-id="${userId}" data-user-email="${escapeHtml(user.email || user.Email)}">
Delete
</button>
@@ -1288,22 +1291,27 @@ function displayUsers(users) {
}
function setupUserActionListeners() {
const tableBody = document.getElementById('users-table-body');
if (!tableBody) return;
const container = document.querySelector('.users-list');
if (!container) return;
// Remove existing listeners by cloning the node
const newTableBody = tableBody.cloneNode(true);
tableBody.parentNode.replaceChild(newTableBody, tableBody);
// Remove existing event listeners by cloning the container
const newContainer = container.cloneNode(true);
container.parentNode.replaceChild(newContainer, container);
// Get the updated reference
const updatedTableBody = document.getElementById('users-table-body');
const updatedContainer = document.querySelector('.users-list');
updatedTableBody.addEventListener('click', function(e) {
updatedContainer.addEventListener('click', function(e) {
if (e.target.classList.contains('delete-user-btn')) {
const userId = e.target.getAttribute('data-user-id');
const userEmail = e.target.getAttribute('data-user-email');
console.log('Delete button clicked for user:', userId);
deleteUser(userId, userEmail);
} else if (e.target.classList.contains('send-login-btn')) {
const userId = e.target.getAttribute('data-user-id');
const userEmail = e.target.getAttribute('data-user-email');
console.log('Send login details button clicked for user:', userId);
sendLoginDetailsToUser(userId, userEmail);
}
});
}
@@ -1333,13 +1341,40 @@ async function deleteUser(userId, userEmail) {
}
}
async function sendLoginDetailsToUser(userId, userEmail) {
if (!confirm(`Send login details to "${userEmail}"?`)) {
return;
}
try {
const response = await fetch(`/api/users/${userId}/send-login-details`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
if (data.success) {
showStatus(`Login details sent to "${userEmail}" successfully`, 'success');
} else {
throw new Error(data.error || 'Failed to send login details');
}
} catch (error) {
console.error('Error sending login details:', error);
showStatus(`Failed to send login details: ${error.message}`, 'error');
}
}
async function createUser(e) {
e.preventDefault();
const email = document.getElementById('user-email').value.trim();
const password = document.getElementById('user-password').value;
const name = document.getElementById('user-name').value.trim();
const admin = document.getElementById('user-admin').checked;
const admin = document.getElementById('user-is-admin').checked;
if (!email || !password) {
showStatus('Email and password are required', 'error');
@@ -1382,7 +1417,7 @@ async function createUser(e) {
}
function clearUserForm() {
const form = document.getElementById('user-form');
const form = document.getElementById('create-user-form');
if (form) {
form.reset();
showStatus('User form cleared', 'info');