import { useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { CustomInput, CustomCheckBox, CustomButton } from "../../../components/custom"; import type { SigninRequest } from "../AuthTypes"; import { useAuth } from "../../../context/AuthContext"; export default function SignInForm() { const navigate = useNavigate(); const [isChecked, setIsChecked] = useState(false); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const [errorMessage, setErrorMessage] = useState(""); const { login } = useAuth(); // Retrieve login function from context const handleSignIn = async (event: React.FormEvent) => { event.preventDefault(); setErrorMessage(""); setIsLoading(true); const payload: SigninRequest = { email, password, }; try { // Use the context login function to ensure state is updated await login(payload, isChecked); // Redirect to the dashboard after successful signin. navigate("/dashboard"); } catch (error) { const message = error instanceof Error ? error.message : "Unable to sign in. Please try again."; setErrorMessage(message); } finally { setIsLoading(false); } }; return (

Sign In

Enter your email and password to sign in!

Or
setEmail(event.target.value)} className="!text-gray-900" /> setPassword(event.target.value)} className="!text-gray-900" /> {errorMessage && (

{errorMessage}

)}
setIsChecked(e.target.checked)} /> Forgot password?
Sign in
{/*

Don't have an account? {""} Sign Up

*/}
); }