import { Box, Button, Stack, Typography } from "@mui/material"; import { useEffect, useState } from "react"; import { useTheme } from "@emotion/react"; import { useDispatch } from "react-redux"; import { useNavigate } from "react-router-dom"; import { createToast } from "../../Utils/toastUtils.jsx"; import { forgotPassword } from "../../Features/Auth/authSlice.js"; import { Trans, useTranslation } from "react-i18next"; import Background from "@/assets/Images/background-grid.svg?react"; import EmailIcon from "@/assets/icons/email.svg?react"; import Logo from "@/assets/icons/checkmate-icon.svg?react"; import IconBox from "@/Components/v1/IconBox/index.jsx"; import "./index.css"; const CheckEmail = () => { const theme = useTheme(); const navigate = useNavigate(); const dispatch = useDispatch(); const { t } = useTranslation(); const [email, setEmail] = useState(); const [disabled, setDisabled] = useState(false); useEffect(() => { setEmail(sessionStorage.getItem("email")); }, []); // TODO - fix const openMail = () => { window.location.href = "mailto:"; }; const toastFail = [ { body: t("auth.forgotPassword.toasts.emailNotFound"), }, { body: t("auth.forgotPassword.toasts.redirect").replace("", "3"), }, { body: t("auth.forgotPassword.toasts.redirect").replace("", "2"), }, { body: t("auth.forgotPassword.toasts.redirect").replace("", "1"), }, ]; const resendToken = async () => { setDisabled(true); // prevent resent button from being spammed if (!email) { let index = 0; const interval = setInterval(() => { if (index < toastFail.length) { createToast(toastFail[index]); index++; } else { clearInterval(interval); navigate("/forgot-password"); } }, 1000); } else { const form = { email: email }; const action = await dispatch(forgotPassword(form)); if (action.payload.success) { createToast({ body: t("auth.forgotPassword.toasts.sent").replace("", form.email), }); setDisabled(false); } else { if (action.payload) { // dispatch errors createToast({ body: action.payload.msg, // FIXME: Potential untranslated string }); } else { // unknown errors createToast({ body: t("common.toasts.unknownError"), }); } } } }; const handleNavigate = () => { sessionStorage.removeItem("email"); navigate("/login"); }; return ( {t("common.appName")} .MuiStack-root": { border: 1, borderRadius: theme.spacing(5), borderColor: theme.palette.primary.lowContrast, backgroundColor: theme.palette.primary.main, padding: { xs: theme.spacing(12), sm: theme.spacing(20), }, }, }} > {t("auth.forgotPassword.heading")} {email || "username@email.com"} ), }} /> ), }} /> ), }} /> ); }; export default CheckEmail;