import { useState } from "react"; import { useFormik } from "formik"; import { Link, useNavigate } from "react-router-dom"; import Spinner from "../../../components/global/Spinner"; import { toaster } from "../../../utils"; import { checkHttpStatus } from "../../../services/helpers"; import { logIn } from "../../../services/auth"; import { LOCAL_STORAGE } from "../../../constants"; import { authLoginSuccess } from "../../../reducers"; interface IProfileProps { dispatch: any; } const Login = (props: IProfileProps) => { const { dispatch } = props; const [loggingIn, setLoggingIn] = useState(false); const navigate = useNavigate(); const formik = useFormik({ initialValues: { username: "", password: "" }, onSubmit: (values) => { const username = values.username; const password = values.password; setLoggingIn(true); if (username && password) { logIn(username, password) .then(checkHttpStatus) .then((data) => { localStorage.setItem( LOCAL_STORAGE, JSON.stringify({ access_token: data.access_token, refresh_token: data.refresh_token }) ); dispatch(authLoginSuccess(data)); navigate("/"); }) .catch((err) => { if (err) { err.text().then((e: string) => { toaster(e, "error"); }); } }) .finally(() => { setLoggingIn(false); }); } } }); return ( <>

Sign in

Create account
); }; export default Login;