// material-ui import { useTheme } from '@mui/material/styles'; import { Box, Button, FormControl, FormHelperText, InputLabel, OutlinedInput } from '@mui/material'; import { useDispatch } from 'react-redux'; import { useNavigate } from 'react-router-dom'; // third party import * as Yup from 'yup'; import { Formik } from 'formik'; // project imports import AnimateButton from 'ui-component/extended/AnimateButton'; import useAuth from 'hooks/useAuth'; import useScriptRef from 'hooks/useScriptRef'; import { SNACKBAR_OPEN } from 'store/actions'; // ========================|| FIREBASE - FORGOT PASSWORD ||======================== // const AuthForgotPassword = ({ ...others }) => { const theme = useTheme(); const scriptedRef = useScriptRef(); const dispatch = useDispatch(); const navigate = useNavigate(); const { resetPassword } = useAuth(); return ( { try { await resetPassword(values.email); if (scriptedRef.current) { setStatus({ success: true }); setSubmitting(false); dispatch({ type: SNACKBAR_OPEN, open: true, message: 'Check mail for reset password link', variant: 'alert', alertSeverity: 'success' }); setTimeout(() => { navigate('/login', { replace: true }); }, 1500); } } catch (err: any) { console.error(err); if (scriptedRef.current) { setStatus({ success: false }); setErrors({ submit: err.message }); setSubmitting(false); } } }} > {({ errors, handleBlur, handleChange, handleSubmit, isSubmitting, touched, values }) => (
Email Address / Username {touched.email && errors.email && ( {errors.email} )} {errors.submit && ( {errors.submit} )}
)}
); }; export default AuthForgotPassword;