import { Button, Input } from "@mui/joy"; import { FormEvent, useState } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { authServiceClient } from "@/grpcweb"; import useLoading from "@/hooks/useLoading"; import useNavigateTo from "@/hooks/useNavigateTo"; import { useUserStore } from "@/stores"; const PasswordAuthForm = () => { const { t } = useTranslation(); const navigateTo = useNavigateTo(); const userStore = useUserStore(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const actionBtnLoadingState = useLoading(false); const allowConfirm = email.length > 0 && password.length > 0; 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 (e: FormEvent) => { e.preventDefault(); if (actionBtnLoadingState.isLoading) { return; } try { actionBtnLoadingState.setLoading(); const user = await authServiceClient.signIn({ email, password }); if (user) { userStore.setCurrentUserId(user.id); await userStore.fetchCurrentUser(); navigateTo("/"); } else { toast.error("Signin failed"); } } catch (error: any) { console.error(error); toast.error(error.details); } actionBtnLoadingState.setFinish(); }; return (
{t("common.email")}
{t("common.password")}
); }; export default PasswordAuthForm;