import React, { ChangeEvent, FormEvent, useState } from "react"; import { useNavigate } from "react-router-dom"; import { catchErrors } from "../helpers"; import { SpinnerIcon } from "../icons"; import { useAuth } from "./auth.context"; export const Login = () => { const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [loginData, setLoginData] = useState({ email: "", password: "" }); const navigate = useNavigate(); const { login } = useAuth(); function handleChange(e: ChangeEvent) { const { name, value } = e.currentTarget; setLoginData({ ...loginData, [name]: value }); } async function handleSubmit(e: FormEvent) { e.preventDefault(); console.log(loginData); const { email, password } = loginData; try { setLoading(true); await login(email, password, () => navigate("/", { replace: true })); } catch (error) { setLoading(false); catchErrors(error, setError); } } return (
{error && (

{error}

)}
); };