import { useState, type FormEvent } from 'react'; import { Navigate, useNavigate } from 'react-router-dom'; import { useAuth } from '../auth/context'; import { APP_ID } from '../api/config'; import { Button } from '../components/buttons'; import { Card, Input } from '../components/reusable'; /** Login gate. Redirects to /orders once authenticated. */ export function LoginPage() { const { authed, login } = useAuth(); const navigate = useNavigate(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [orgId, setOrgId] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); if (authed) return ; async function submit(e: FormEvent) { e.preventDefault(); setBusy(true); setError(null); try { await login(email, password, orgId || undefined); navigate('/orders', { replace: true }); } catch (err) { setError((err as { message?: string })?.message ?? 'Login failed'); } finally { setBusy(false); } } return (

Krishna Sales

Field Sales console · Sandbox {APP_ID}

setEmail(e.target.value)} required autoFocus /> setPassword(e.target.value)} required /> setOrgId(e.target.value)} /> {error &&
{error}
}
); }