import { useState, useEffect } from 'react'; import { GithubOutlined } from '@ant-design/icons'; import { useNavigate, Link } from 'react-router'; import { toast } from 'sonner'; import { Icon } from '@iconify/react'; import { useAuthStore } from '../../features/auth/store/auth.store'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; const loginSchema = z.object({ email: z.string().min(1, 'Email is required').email('Please enter a valid email'), password: z.string().min(1, 'Password is required'), }); type LoginForm = z.infer; export default function LoginPage() { const navigate = useNavigate(); const login = useAuthStore((state) => state.login); const isAuthenticated = useAuthStore((state) => state.isAuthenticated); const [isGithubLoading, setIsGithubLoading] = useState(false); const [error, setError] = useState(null); const [showPassword, setShowPassword] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const { register, handleSubmit, formState: { errors, isValid } } = useForm({ resolver: zodResolver(loginSchema), mode: 'onChange', defaultValues: { email: '', password: '' }, }); useEffect(() => { if (isAuthenticated) navigate('/'); }, [isAuthenticated, navigate]); const onSubmit = handleSubmit(async (data) => { setError(null); setIsSubmitting(true); try { const success = await login(data.email, data.password); if (success) { toast.success('Login successful!'); navigate('/'); } else setError('Login failed. Please check your credentials.'); } catch { setError('Login failed. Please try again.'); } finally { setIsSubmitting(false); } }); return (

Welcome Back

Sign in to QR Campaign Manager

{error && (

{error}

)}
{errors.email &&

{errors.email.message}

}
Forgot password?
{errors.password &&

{errors.password.message}

}
OR

Don't have an account? Sign up

By signing in, you agree to our Terms of Service and Privacy Policy

); }