[deploy] Harden dashboard event listeners for missing elements
All checks were successful
Deploy Discord Bot / deploy (push) Successful in 36s

This commit is contained in:
Pascal Prießnitz
2025-12-04 12:19:26 +01:00
parent 78578fcc1c
commit bebca808b0

View File

@@ -2312,43 +2312,55 @@ router.get('/', (req, res) => {
} }
} }
document.getElementById('settingsForm').addEventListener('submit', async (e) => { const settingsForm = document.getElementById('settingsForm');
if (settingsForm) {
settingsForm.addEventListener('submit', async (e) => {
e.preventDefault(); e.preventDefault();
if (!currentGuild) return; if (!currentGuild) return;
const form = new FormData(e.currentTarget); const form = new FormData(e.currentTarget as HTMLFormElement);
const payload = Object.fromEntries(form.entries()); const payload: any = Object.fromEntries(form.entries());
payload.supportRoleId = payload.supportRoleId || undefined; payload.supportRoleId = payload.supportRoleId || undefined;
payload.guildId = currentGuild; payload.guildId = currentGuild;
const res = await fetch('/api/settings', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(payload) }); const res = await fetch('/api/settings', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(payload) });
document.getElementById('saveStatus').textContent = res.ok ? 'Gespeichert' : 'Fehler'; const saveStatus = document.getElementById('saveStatus');
if (saveStatus) saveStatus.textContent = res.ok ? 'Gespeichert' : 'Fehler';
if (res.ok) { if (res.ok) {
await loadSettings(currentGuild); await loadSettings(currentGuild);
await loadModules(); await loadModules();
} }
}); });
}
document.getElementById('openPanelModal').addEventListener('click', () => { const openPanelModalBtn = document.getElementById('openPanelModal');
document.getElementById('panelStatus').textContent = ''; if (openPanelModalBtn) {
openPanelModalBtn.addEventListener('click', () => {
const panelStatus = document.getElementById('panelStatus');
if (panelStatus) panelStatus.textContent = '';
showModal(panelModal); showModal(panelModal);
}); });
}
if (openSupportLogin) openSupportLogin.addEventListener('click', () => { showModal(supportLoginModal); }); if (openSupportLogin) openSupportLogin.addEventListener('click', () => { showModal(supportLoginModal); });
if (supportLoginSave) supportLoginSave.addEventListener('click', saveSupportLogin); if (supportLoginSave) supportLoginSave.addEventListener('click', saveSupportLogin);
if (refreshSupportStatus) refreshSupportStatus.addEventListener('click', loadSupportLogin); if (refreshSupportStatus) refreshSupportStatus.addEventListener('click', loadSupportLogin);
document.getElementById('panelSubmit').addEventListener('click', async () => { const panelSubmit = document.getElementById('panelSubmit');
if (panelSubmit) {
panelSubmit.addEventListener('click', async () => {
if (!currentGuild) return; if (!currentGuild) return;
const form = new FormData(document.getElementById('panelForm')); const formEl = document.getElementById('panelForm') as HTMLFormElement | null;
const channelId = form.get('channelId'); const form = formEl ? new FormData(formEl) : null;
const panelTitle = form.get('panelTitle'); const channelId = form?.get('channelId');
const panelDescription = form.get('panelDescription'); const panelTitle = form?.get('panelTitle');
const panelCategories = form.get('panelCategories'); const panelDescription = form?.get('panelDescription');
const panelCategories = form?.get('panelCategories');
const status = document.getElementById('panelStatus'); const status = document.getElementById('panelStatus');
const ok = await createPanel(channelId, panelTitle, panelDescription, panelCategories); const ok = await createPanel(channelId, panelTitle, panelDescription, panelCategories);
if (status) status.textContent = ok ? 'Panel gesendet' : 'Fehler beim Senden'; if (status) status.textContent = ok ? 'Panel gesendet' : 'Fehler beim Senden';
showToast(ok ? 'Ticket-Panel gesendet' : 'Ticket-Panel Fehler', !ok); showToast(ok ? 'Ticket-Panel gesendet' : 'Ticket-Panel Fehler', !ok);
if (ok) hideModal(); if (ok) hideModal();
}); });
}
document.querySelectorAll('[data-close-modal]').forEach((btn) => btn.addEventListener('click', hideModal)); document.querySelectorAll('[data-close-modal]').forEach((btn) => btn.addEventListener('click', hideModal));
modalBackdrop.addEventListener('click', hideModal); modalBackdrop.addEventListener('click', hideModal);