import React from "react"; import { useTranslation } from "react-i18next"; import Modal from "../ui/Modal"; import { sendAuthToken } from "../utils/api"; import useAuth from "../hooks/useAuth"; import { toast } from "react-toastify"; import Waiter from "../ui/Waiter"; const Account = ({ disabled, ...props }) => { const { t } = useTranslation(); const { isAuthenticated, logout } = useAuth(); const [email, setEmail] = React.useState(""); const [emailSent, setEmailSent] = React.useState(false); const [showLogin, setShowLogin] = React.useState(false); const [loginInProgress, setLoginInProgress] = React.useState(false); const handleChange = (e) => { setEmail(e.target.value); }; const handleSubmit = async () => { try { setLoginInProgress(true); await sendAuthToken(email); setEmailSent(true); setLoginInProgress(false); } catch (e) { setLoginInProgress(false); console.log(e); toast.error(t("Error while logging, verify your email address")); } }; const showAlert = () => { alert(t("Cookie are disabled or not yet accepted, can't connect")); }; React.useEffect(() => { if (!showLogin) { setEmail(""); setEmailSent(false); } }, [showLogin]); if (disabled) { return (
); } const handleKeyDown = (e) => { if (e.key === "Enter") { handleSubmit(); } }; return ( <>
{isAuthenticated ? ( ) : ( )}
{loginInProgress && } {!emailSent && ( <>
)} {emailSent && ( <>

{t("Mail sent, check your inbox and click the link to login.")}

)}
); }; export default Account;