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"; import { createToast } from "../../Utils/toastUtils"; import { forgotPassword } from "../../Features/Auth/authSlice"; import Background from "../../assets/Images/background-grid.svg?react"; import EmailIcon from "../../assets/icons/email.svg?react"; import Logo from "../../assets/icons/bwu-icon.svg?react"; import IconBox from "../../Components/IconBox"; import "./index.css"; const CheckEmail = () => { const theme = useTheme(); const navigate = useNavigate(); const dispatch = useDispatch(); 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: "Email not found.", }, { body: "Redirecting in 3...", }, { body: "Redirecting in 2...", }, { body: "Redirecting in 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: `Instructions sent to ${form.email}.`, }); setDisabled(false); } else { if (action.payload) { // dispatch errors createToast({ body: action.payload.msg, }); } else { // unknown errors createToast({ body: "Unknown error.", }); } } } }; const handleNavigate = () => { sessionStorage.removeItem("email"); navigate("/login"); }; return ( BlueWave Uptime .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), }, }, }} > Check your email We sent a password reset link to{" "} {email || "username@email.com"} Didn't receive the email?{" "} Click to resend Go back to — Log In ); }; export default CheckEmail;