Skip to content

Commit a0c41a7

Browse files
Merge pull request #2247 from bryanjenningz/remove-unnecessary-forgotpassword-full-page-load
Remove unnecessary forgot-password full page load
2 parents 7af5b27 + 97339b0 commit a0c41a7

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

__tests__/pages/__snapshots__/forgotpassword.test.js.snap

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,12 @@ exports[`ForgotPassword Page Should render invalid user/email form on error 1`]
182182
<p
183183
class="card-text"
184184
/>
185-
<a
185+
<button
186186
class="btn btn-primary btn-lg btn-block mb-3"
187-
href="/forgotpassword"
188-
role="button"
187+
data-testid="back"
189188
>
190189
Go Back
191-
</a>
190+
</button>
192191
</div>
193192
</div>
194193
</div>

__tests__/pages/forgotpassword.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,11 @@ describe('ForgotPassword Page', () => {
112112

113113
// wait for mutation updates after submitButton is clicked
114114
await waitFor(() => expect(container).toMatchSnapshot())
115+
116+
const backButton = getByTestId('back')
117+
118+
await waitFor(() => fireEvent.click(backButton))
119+
120+
await waitFor(() => getByRole('heading', { name: /reset your password/i }))
115121
})
116122
})

pages/forgotpassword.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useMutation } from '@apollo/client'
2-
import React from 'react'
1+
import { ApolloError, useMutation } from '@apollo/client'
2+
import React, { useState } from 'react'
33
import { Formik, Form, Field } from 'formik'
44
import RESET_PASSWORD from '../graphql/queries/resetPassword'
55
import { resetPasswordValidation } from '../helpers/formValidation'
@@ -12,7 +12,10 @@ const initialValues = {
1212
}
1313

1414
export const ResetPassword: React.FC = () => {
15-
const [reqPwReset, { data, error }] = useMutation(RESET_PASSWORD)
15+
const [error, setError] = useState<null | ApolloError>(null)
16+
const [reqPwReset, { data }] = useMutation(RESET_PASSWORD, {
17+
onError: setError
18+
})
1619
const handleSubmit = async ({ userOrEmail }: { userOrEmail: string }) => {
1720
try {
1821
await reqPwReset({ variables: { userOrEmail } })
@@ -27,17 +30,16 @@ export const ResetPassword: React.FC = () => {
2730
</Card>
2831
)
2932
}
30-
// Can't use NavLink since page needs to reload.
3133
if (error) {
3234
return (
3335
<Card title="Username or Email does not exist">
34-
<a
35-
href="/forgotpassword"
36+
<button
3637
className="btn btn-primary btn-lg btn-block mb-3"
37-
role="button"
38+
onClick={() => setError(null)}
39+
data-testid="back"
3840
>
3941
Go Back
40-
</a>
42+
</button>
4143
</Card>
4244
)
4345
}

0 commit comments

Comments
 (0)