fix(web): SMTP-Speichern zeigte fälschlich "Server nicht erreichbar"
Das Formular griff nach dem await auf e.currentTarget zu, um das Passwortfeld zu leeren. React setzt currentTarget nach der Event- Verarbeitung auf null, wodurch eine normale (keine ApiError-)Exception flog und die generische Netzwerkfehler-Meldung angezeigt wurde – obwohl das Speichern selbst serverseitig erfolgreich war. Die Formularreferenz wird jetzt vor dem await festgehalten. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
a68b4cf6ec
commit
bbece6ca5f
1 changed files with 3 additions and 2 deletions
|
|
@ -20,11 +20,12 @@ function SmtpForm({ s, w, onSaved }: { s: Settings; w: boolean; onSaved: () => v
|
||||||
const [testTo, setTestTo] = useState(''); const [testBusy, setTestBusy] = useState(false);
|
const [testTo, setTestTo] = useState(''); const [testBusy, setTestBusy] = useState(false);
|
||||||
async function save(e: FormEvent<HTMLFormElement>) {
|
async function save(e: FormEvent<HTMLFormElement>) {
|
||||||
e.preventDefault(); if (!w) return; setBusy(true); setMsg(null);
|
e.preventDefault(); if (!w) return; setBusy(true); setMsg(null);
|
||||||
const f = new FormData(e.currentTarget); const v = (k: string) => (String(f.get(k) ?? '').trim() || null);
|
const form = e.currentTarget;
|
||||||
|
const f = new FormData(form); const v = (k: string) => (String(f.get(k) ?? '').trim() || null);
|
||||||
const pw = String(f.get('password') ?? '');
|
const pw = String(f.get('password') ?? '');
|
||||||
try {
|
try {
|
||||||
await api('PUT', '/admin/email/settings', { host: v('host'), port: Number(f.get('port')) || 587, secureMode: f.get('secureMode'), username: v('username'), fromName: v('fromName'), fromEmail: v('fromEmail'), ...(pw ? { password: pw } : {}) });
|
await api('PUT', '/admin/email/settings', { host: v('host'), port: Number(f.get('port')) || 587, secureMode: f.get('secureMode'), username: v('username'), fromName: v('fromName'), fromEmail: v('fromEmail'), ...(pw ? { password: pw } : {}) });
|
||||||
setMsg({ k: 'ok', t: 'Gespeichert.' }); (e.currentTarget.elements.namedItem('password') as HTMLInputElement).value = ''; onSaved();
|
setMsg({ k: 'ok', t: 'Gespeichert.' }); (form.elements.namedItem('password') as HTMLInputElement).value = ''; onSaved();
|
||||||
} catch (x) { setMsg({ k: 'err', t: errMsg(x) }); } finally { setBusy(false); }
|
} catch (x) { setMsg({ k: 'err', t: errMsg(x) }); } finally { setBusy(false); }
|
||||||
}
|
}
|
||||||
async function sendTest() {
|
async function sendTest() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue