Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CUTL-133] 🔄 (Login/Forgot Password/Register) Store email so that we can share it across pages #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[CUTL-133] 🔄 (Login/Forgot Password) Store email so that we can sha…
…re it across both pages

--
mcgomez committed Feb 23, 2022
commit 633a813f4cb15027be362b3b4bb0516509491753
12 changes: 9 additions & 3 deletions app/pages/Login/Login.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
<FormField
label="Email"
name="email"
onChange={e => 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 }) => {
/>
</Box>

<Link to="/password-reset-request">Forgot Password?</Link>
<Link to={{ pathname: '/password-reset-request', state: { email } }}>
Forgot Password?
</Link>

{/* Status Messages */}
<Box>{error && <Message message={error} isError />}</Box>
6 changes: 5 additions & 1 deletion app/pages/PasswordReset/PasswordReset.js
Original file line number Diff line number Diff line change
@@ -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 },
25 changes: 20 additions & 5 deletions app/pages/PasswordResetRequest/PasswordResetRequest.js
Original file line number Diff line number Diff line change
@@ -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}
>
<TextInput type="email" />
<TextInput type="email" value={email} />
</FormField>

{/* Submit */}
@@ -78,4 +89,8 @@ const PasswordResetRequest = () => {
)
}

PasswordResetRequest.propTypes = {
location: PropTypes.object.isRequired,
}

export default PasswordResetRequest