From 8379207241c68b1602b57f9f25ea402054722ee3 Mon Sep 17 00:00:00 2001 From: Pham Hai Duong Date: Mon, 2 Dec 2019 18:32:03 +0700 Subject: [PATCH] [CLD-490] Create success page for forgot-password (#178) --- .../forgot-password-form.tsx.snap | 25 ++++++++++++++++++ .../__tests__/forgot-password-form.tsx | 26 ++++++++++++++++++- .../forgot-password/forgot-password-form.tsx | 22 +++++++++++++++- src/sagas/__tests__/forgot-password.ts | 2 +- src/sagas/forgot-password.ts | 2 +- 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap b/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap index f84cfac364..3ecc5f9f6f 100644 --- a/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap +++ b/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap @@ -61,3 +61,28 @@ exports[`ForgotPasswordForm should match snapshot 2`] = ` `; + +exports[`ForgotPasswordForm should match snapshot 3`] = ``; + +exports[`SuccessForgetPasswordContent should match snapshot 1`] = ` + +
+ Success +
+ + Please check your inbox for an email we have just sent you with instructions for how to reset your password. + +
+ + Click here to return to the login page + +
+`; diff --git a/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx b/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx index cc50bb7d7d..3724a84eff 100644 --- a/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx +++ b/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx @@ -7,7 +7,8 @@ import { mapPropsToValues, ForgotPasswordValues, handleSubmitForgotPassword, - ForgotPasswordFormProps + ForgotPasswordFormProps, + SuccessForgetPasswordContent } from '../forgot-password-form' describe('ForgotPasswordForm', () => { @@ -38,6 +39,22 @@ describe('ForgotPasswordForm', () => { expect(wrapper.find('[dataTest="email"]')).toHaveLength(1) }) + it('should match snapshot', () => { + const mockProps = { + ...mockWithFormik({ email: '1' }), + ...getMockRouterProps({}), + location: { + hash: '', + key: '', + pathname: '', + search: '?isSuccess=1', + state: {} + } + } as ForgotPasswordFormProps + const wrapper = shallow() + expect(wrapper).toMatchSnapshot() + }) + describe('mapPropsToValues', () => { it('should run correctly', () => { const result = mapPropsToValues() @@ -72,3 +89,10 @@ describe('ForgotPasswordForm', () => { }) }) }) + +describe('SuccessForgetPasswordContent', () => { + it('should match snapshot', () => { + const wrapper = shallow() + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/src/components/pages/forgot-password/forgot-password-form.tsx b/src/components/pages/forgot-password/forgot-password-form.tsx index eb5316614f..9db56d9702 100644 --- a/src/components/pages/forgot-password/forgot-password-form.tsx +++ b/src/components/pages/forgot-password/forgot-password-form.tsx @@ -11,9 +11,25 @@ import { Form, withFormik, FormikProps, - FormikBag + FormikBag, + H5, + FlexContainerBasic } from '@reapit/elements' import { withRouter, RouteComponentProps } from 'react-router' +import { Link } from 'react-router-dom' + +export const SuccessForgetPasswordContent: React.FC = () => { + return ( + +
Success
+ + Please check your inbox for an email we have just sent you with instructions for how to reset your password. + +
+ Click here to return to the login page +
+ ) +} export type ForgotPasswordFormProps = FormikProps & RouteComponentProps @@ -24,6 +40,10 @@ export const ForgotPasswordForm: React.FC = ({ location }) => { const isError = location.search === '?isError=1' + const isSuccess = location.search === '?isSuccess=1' + if (isSuccess) { + return + } return (
Please enter your email address to reset your password diff --git a/src/sagas/__tests__/forgot-password.ts b/src/sagas/__tests__/forgot-password.ts index a8c42a5807..7d322c9527 100644 --- a/src/sagas/__tests__/forgot-password.ts +++ b/src/sagas/__tests__/forgot-password.ts @@ -17,7 +17,7 @@ describe('requestForgotPassword', () => { expect(gen.next().value).toEqual(call(callAPIForgotPassword, 'abc@gmail.com')) it('should call API success', () => { const clone = gen.clone() - expect(clone.next({ CodeDeliveryDetails: {} }).value).toEqual(history.push(Routes.DEVELOPER_RESET_PASSWORD)) + expect(clone.next({ CodeDeliveryDetails: {} }).value).toEqual(history.push(`${Routes.FORGOT_PASSWORD}?isSuccess=1`)) expect(clone.next().value).toEqual(put(forgotPasswordLoading(false))) expect(clone.next().done).toEqual(true) }) diff --git a/src/sagas/forgot-password.ts b/src/sagas/forgot-password.ts index 6743e2f718..6926d09d6a 100644 --- a/src/sagas/forgot-password.ts +++ b/src/sagas/forgot-password.ts @@ -26,7 +26,7 @@ export const requestForgotPassword = function*({ data: email }) { try { const response = yield call(callAPIForgotPassword, email) if (response.CodeDeliveryDetails) { - yield history.push(Routes.DEVELOPER_RESET_PASSWORD) + yield history.push(`${Routes.FORGOT_PASSWORD}?isSuccess=1`) } } catch (error) { console.error(error.message)