import { Button, Input } from "@mui/joy"; import React, { useEffect, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { toast } from "react-hot-toast"; import * as api from "../helpers/api"; import { useAppSelector } from "../stores"; import useLoading from "../hooks/useLoading"; import useUserStore from "../stores/v1/user"; const SignIn: React.FC = () => { const navigate = useNavigate(); const userStore = useUserStore(); const { workspaceProfile: { disallowSignUp }, } = useAppSelector((state) => state.global); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const actionBtnLoadingState = useLoading(false); const allowConfirm = email.length > 0 && password.length > 0; useEffect(() => { if (userStore.getCurrentUser()) { return navigate("/", { replace: true, }); } }, []); const handleEmailInputChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setEmail(text); }; const handlePasswordInputChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setPassword(text); }; const handleSigninBtnClick = async () => { if (actionBtnLoadingState.isLoading) { return; } try { actionBtnLoadingState.setLoading(); await api.signin(email, password); const user = await userStore.fetchCurrentUser(); if (user) { navigate("/", { replace: true, }); } else { toast.error("Signin failed"); } } catch (error: any) { console.error(error); toast.error(error.response.data.message); } actionBtnLoadingState.setFinish(); }; return (
logo Shortify
Email
Password
{!disallowSignUp && (

{"Don't have an account yet?"} Sign up

)}
); }; export default SignIn;