import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { Link } from 'react-router'; import { Card } from '@/components/Card'; import { useState } from 'react'; import { toast } from 'sonner'; import { useForm } from 'hooks/useForm'; import { useAuth } from 'hooks/useAuth'; import { useGlobal } from 'hooks/useGlobal'; import { useTranslation } from '@/lib/i18n'; const initialState: LoginFormState = { // email: 'pastilhas@pastilhas.dev', // password: '', }; export function Login() { const { t } = useTranslation(); const [isSubmitting, setIsSubmitting] = useState(false); const { state, formRef, update, isValid } = useForm(initialState, validateForm); const { signin } = useAuth(); const [, setDuckHidden] = useGlobal('DUCK_HIDDEN', false); const handleSubmit = async (ev: React.FormEvent) => { ev.preventDefault(); if (!isValid || isSubmitting) return; setIsSubmitting(true); setDuckHidden(true); try { await signin({ email: state.email!, password: state.password! }); window.location.href = '/'; } catch (ex) { const error = ex as { message?: string }; toast.error(error.message || 'Login failed. Please try again.'); update({ ...state, password: '' }); } finally { setIsSubmitting(false); } }; return (
{t('auth.signInTitle')}
{t('auth.signInSubtitle')}
{/*

*/} {/* Don't have an account?{' '} */} {/* */} {/* Register */} {/* */} {/*

*/}

{t('auth.forgotPassword')}

); } type LoginFormState = { email?: string; password?: string; }; const validateForm = (state: Partial) => { const { email, password } = state; if (!email || !password) return false; return true; };