fix: confirmRemoveInactive now auto-saves immediately; save button no longer gets stuck

This commit is contained in:
James 2026-03-20 01:42:25 -04:00
parent 3a1520cc91
commit 71d481c43b
1 changed files with 27 additions and 4 deletions

View File

@ -536,24 +536,47 @@
if (window._rescrapeNotFound) window._rescrapeNotFound[idx] = null;
}
function confirmRemoveInactive(idx) {
async function confirmRemoveInactive(idx) {
const people = window._rescrapeNotFound || [];
const p = people[idx];
if (!p) return;
const name = p.name || p.email || 'this person';
if (!confirm('Remove ' + name + ' from the organization? This cannot be undone.')) return;
// Remove from editingMembers by matching email or name
editingMembers = editingMembers.filter(m => {
if (p.email && m.email && m.email.toLowerCase() === p.email.toLowerCase()) return false;
if (p.name && m.name && m.name.toLowerCase() === p.name.toLowerCase()) return false;
return true;
});
// Remove from notFound list and re-render
window._rescrapeNotFound = people.filter((_, i) => i !== idx);
renderMemberList();
// Re-render the not-found section
const nfEl = document.querySelector('#rescrapeContent .border-t');
if (window._rescrapeNotFound.length === 0 && nfEl) nfEl.remove();
// Save immediately
const orgIdSnapshot = editingOrgId;
const membersSnapshot = editingMembers.slice();
const saveBtn = document.getElementById('saveOrgBtn');
if (saveBtn) { saveBtn.disabled = true; saveBtn.textContent = 'Saving...'; }
try {
const freshRes = await fetchAPI('/api/orgs/' + orgIdSnapshot);
const freshOrg = await freshRes.json();
const mRes = await fetchAPI('/api/orgs/' + orgIdSnapshot + '/members', {
method: 'PUT',
body: JSON.stringify({ members: membersSnapshot, version: freshOrg.version || 1 })
});
const mData = await mRes.json();
if (!mRes.ok) throw new Error(mData.error || 'Failed');
const vEl = document.getElementById('eVersion');
if (vEl) vEl.value = mData.version;
if (window._orgsMap && window._orgsMap[orgIdSnapshot]) {
window._orgsMap[orgIdSnapshot].version = mData.version;
window._orgsMap[orgIdSnapshot].members = membersSnapshot;
}
} catch(e) {
const errEl = document.getElementById('editModalError');
if (errEl) { errEl.textContent = 'Remove failed: ' + e.message; errEl.classList.remove('hidden'); setTimeout(() => errEl.classList.add('hidden'), 4000); }
} finally {
if (saveBtn) { saveBtn.disabled = false; saveBtn.textContent = 'Save Changes'; }
}
}
function toggleScrapeExpand(i) {