import { useForm, router } from '@inertiajs/react'; import InputError from '@/components/input-error'; import TextLink from '@/components/text-link'; import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import AuthLayout from '@/layouts/auth-layout'; import { register } from '@/routes'; import { request } from '@/routes/password'; import { Head } from '@inertiajs/react'; import { LoaderCircle } from 'lucide-react'; interface LoginProps { status?: string; canResetPassword: boolean; } export default function Login({ status, canResetPassword }: LoginProps) { const { data, setData, post, processing, errors } = useForm({ email: '', password: '', remember: false, }); const submit = (e: React.FormEvent) => { e.preventDefault(); post('/login', { preserveState: true, onSuccess: () => { console.log('Login successful'); }, onError: (errors: Record) => { console.log('Login errors:', errors); }, }); }; React.useEffect(() => { if (Object.keys(errors).length > 0) { window.scrollTo({ top: 0, behavior: 'smooth' }); } }, [errors]); return (
setData('email', e.target.value)} />
{canResetPassword && ( Forgot password? )}
setData('password', e.target.value)} />
setData('remember', Boolean(checked))} />
Don't have an account?{' '} Sign up
{status &&
{status}
} {Object.keys(errors).length > 0 && (

{Object.values(errors).join(' ')}

)}
); }