diff --git a/app/pages/Login/Login.js b/app/pages/Login/Login.js index 3babccf..87a2900 100644 --- a/app/pages/Login/Login.js +++ b/app/pages/Login/Login.js @@ -29,8 +29,11 @@ const Login = ({ location }) => { const { message: error, showMessage: showError } = useFlashMessage(null) const { message: redirectedMessage, showMessage: showRedirectedMessage } = useFlashMessage(null) + // State const [loading, setLoading] = useState(false) + const [email, setEmail] = useState('') + // Context const { setCurrentUser, setCurrentTokens } = useContext(UserStoreContext) /** @@ -78,10 +81,11 @@ const Login = ({ location }) => { setEmail(e.target.value)} required validate={[ - email => { - if (email && !isEmail(email)) return 'Please enter a valid email address' + e => { + if (e && !isEmail(e)) return 'Please enter a valid email address' return undefined }, ]} @@ -115,7 +119,9 @@ const Login = ({ location }) => { /> - Forgot Password? + + Forgot Password? + {/* Status Messages */} {error && } diff --git a/app/pages/PasswordReset/PasswordReset.js b/app/pages/PasswordReset/PasswordReset.js index f3001fa..b73ad26 100644 --- a/app/pages/PasswordReset/PasswordReset.js +++ b/app/pages/PasswordReset/PasswordReset.js @@ -31,11 +31,15 @@ import { RootStoreContext } from '../../stores/RootStore' * */ const PasswordReset = observer(({ location }) => { + // Message + const { message: error, showMessage: showError } = useFlashMessage(null) + + // State const [loading, setLoading] = useState(false) const [redirect, setRedirect] = useState(false) const [tokenError, setTokenError] = useState(false) - const { message: error, showMessage: showError } = useFlashMessage(null) + // Context const { clearStore, user: { isAuthenticated }, diff --git a/app/pages/PasswordResetRequest/PasswordResetRequest.js b/app/pages/PasswordResetRequest/PasswordResetRequest.js index 3b6b2f2..1927a68 100644 --- a/app/pages/PasswordResetRequest/PasswordResetRequest.js +++ b/app/pages/PasswordResetRequest/PasswordResetRequest.js @@ -1,6 +1,7 @@ /* @flow */ import React, { useEffect, useState } from 'react' import { isEmail } from 'validator' +import PropTypes from 'prop-types' // Components import { Box } from 'components/Box' @@ -23,12 +24,21 @@ import { forgotPassword } from '../../services/user.service' * PasswordResetRequest * */ -const PasswordResetRequest = () => { +const PasswordResetRequest = ({ location }) => { + // Mesage const { message: error, showMessage: showError } = useFlashMessage(null) + // State const [loading, setLoading] = useState(false) - const [success, setSuccess] = useState(false) + const [email, setEmail] = useState('') + + useEffect(() => { + if (location && location.state && location.state.email) { + setEmail(location.state.email) + } + }, []) + useEffect(() => { document.getElementById('reset-password-request-form').reset() }, [success]) @@ -55,13 +65,14 @@ const PasswordResetRequest = () => { name="email" required validate={[ - email => { - if (email && !isEmail(email)) return 'Please enter a valid email address' + e => { + if (e && !isEmail(e)) return 'Please enter a valid email address' return undefined }, ]} + value={email} > - + {/* Submit */} @@ -78,4 +89,8 @@ const PasswordResetRequest = () => { ) } +PasswordResetRequest.propTypes = { + location: PropTypes.object.isRequired, +} + export default PasswordResetRequest