/* global React */ const { useState: useStateAuth, useEffect: useEffectAuth } = React; window.LoginScreen = function LoginScreen({ onAuthed }) { const [mode, setMode] = useStateAuth('login'); // 'login' | 'forgot' | 'sent' const [email, setEmail] = useStateAuth(''); const [password, setPassword] = useStateAuth(''); const [busy, setBusy] = useStateAuth(false); const [error, setError] = useStateAuth(''); async function submitLogin(e) { e.preventDefault(); setError(''); setBusy(true); try { const user = await window.LQ.login(email.trim().toLowerCase(), password); onAuthed && onAuthed(user); } catch (err) { setError(err.message || 'Login failed.'); } finally { setBusy(false); } } async function submitForgot(e) { e.preventDefault(); setError(''); setBusy(true); try { await window.LQ.requestReset(email.trim().toLowerCase()); setMode('sent'); } catch (err) { setError(err.message || 'Request failed.'); } finally { setBusy(false); } } return (
Enter your email to receive a reset link.
> )} {mode === 'sent' && ( <>If {email} matches an admin account, a reset link has been sent. The link expires in 30 minutes.
> )}