From 768139bb4c21dd95897ad9dddc1612b84f74a7ae Mon Sep 17 00:00:00 2001 From: Vu Nguyen Date: Fri, 20 Mar 2020 22:56:28 +0700 Subject: [PATCH] feat: #70 - Cleanup legacy forgotten password flow (#670) --- .../src/actions/__tests__/forgot-password.ts | 14 -- .../src/actions/__tests__/reset-password.ts | 12 -- .../src/actions/forgot-password.ts | 5 - .../marketplace/src/actions/reset-password.ts | 11 -- .../forgot-password-form.tsx.snap | 88 ------------ .../__snapshots__/forgot-password.tsx.snap | 55 -------- .../__tests__/forgot-password-form.tsx | 101 -------------- .../__tests__/forgot-password.tsx | 70 ---------- .../forgot-password/forgot-password-form.tsx | 101 -------------- .../pages/forgot-password/forgot-password.tsx | 50 ------- .../reset-password-form.tsx.snap | 42 ------ .../__snapshots__/reset-password.tsx.snap | 27 ---- .../__tests__/reset-password-form.tsx | 116 ---------------- .../__tests__/reset-password.tsx | 10 -- .../components/pages/reset-password/index.tsx | 3 - .../reset-password/reset-password-form.tsx | 126 ------------------ .../pages/reset-password/reset-password.tsx | 22 --- .../__tests__/__snapshots__/router.tsx.snap | 22 --- packages/marketplace/src/core/router.tsx | 5 - packages/marketplace/src/core/store.ts | 8 -- .../src/reducers/__tests__/forgot-password.ts | 22 --- .../src/reducers/__tests__/reset-password.ts | 22 --- .../src/reducers/forgot-password.ts | 24 ---- .../src/reducers/reset-password.ts | 27 ---- .../src/sagas/__tests__/forgot-password.ts | 70 ---------- .../src/sagas/__tests__/reset-password.ts | 92 ------------- .../marketplace/src/sagas/forgot-password.ts | 36 ----- .../marketplace/src/sagas/reset-password.ts | 46 ------- packages/marketplace/src/types/core.ts | 4 - .../utils/form/__tests__/reset-password.ts | 33 ----- .../src/utils/form/reset-password.ts | 18 --- 31 files changed, 1282 deletions(-) delete mode 100644 packages/marketplace/src/actions/__tests__/forgot-password.ts delete mode 100644 packages/marketplace/src/actions/__tests__/reset-password.ts delete mode 100644 packages/marketplace/src/actions/forgot-password.ts delete mode 100644 packages/marketplace/src/actions/reset-password.ts delete mode 100644 packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap delete mode 100644 packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password.tsx.snap delete mode 100644 packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx delete mode 100644 packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password.tsx delete mode 100644 packages/marketplace/src/components/pages/forgot-password/forgot-password-form.tsx delete mode 100644 packages/marketplace/src/components/pages/forgot-password/forgot-password.tsx delete mode 100644 packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password-form.tsx.snap delete mode 100644 packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password.tsx.snap delete mode 100644 packages/marketplace/src/components/pages/reset-password/__tests__/reset-password-form.tsx delete mode 100644 packages/marketplace/src/components/pages/reset-password/__tests__/reset-password.tsx delete mode 100644 packages/marketplace/src/components/pages/reset-password/index.tsx delete mode 100644 packages/marketplace/src/components/pages/reset-password/reset-password-form.tsx delete mode 100644 packages/marketplace/src/components/pages/reset-password/reset-password.tsx delete mode 100644 packages/marketplace/src/reducers/__tests__/forgot-password.ts delete mode 100644 packages/marketplace/src/reducers/__tests__/reset-password.ts delete mode 100644 packages/marketplace/src/reducers/forgot-password.ts delete mode 100644 packages/marketplace/src/reducers/reset-password.ts delete mode 100644 packages/marketplace/src/sagas/__tests__/forgot-password.ts delete mode 100644 packages/marketplace/src/sagas/__tests__/reset-password.ts delete mode 100644 packages/marketplace/src/sagas/forgot-password.ts delete mode 100644 packages/marketplace/src/sagas/reset-password.ts delete mode 100644 packages/marketplace/src/utils/form/__tests__/reset-password.ts delete mode 100644 packages/marketplace/src/utils/form/reset-password.ts diff --git a/packages/marketplace/src/actions/__tests__/forgot-password.ts b/packages/marketplace/src/actions/__tests__/forgot-password.ts deleted file mode 100644 index d342955aa6..0000000000 --- a/packages/marketplace/src/actions/__tests__/forgot-password.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { submitEmail, forgotPasswordLoading } from '../forgot-password' -import ActionTypes from '../../constants/action-types' - -describe('forgotPassword actions', () => { - it('should create a submitEmail action', () => { - expect(submitEmail.type).toEqual(ActionTypes.FORGOT_PASSWORD_SUBMIT_EMAIL) - expect(submitEmail('abc@gmail.com').data).toEqual('abc@gmail.com') - }) - - it('should create a forgotPasswordLoading action', () => { - expect(forgotPasswordLoading.type).toEqual(ActionTypes.FORGOT_PASSWORD_LOADING) - expect(forgotPasswordLoading(true).data).toEqual(true) - }) -}) diff --git a/packages/marketplace/src/actions/__tests__/reset-password.ts b/packages/marketplace/src/actions/__tests__/reset-password.ts deleted file mode 100644 index 8a44aedc7f..0000000000 --- a/packages/marketplace/src/actions/__tests__/reset-password.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { resetPassword, resetPasswordLoading } from '../reset-password' -import ActionTypes from '../../constants/action-types' - -describe('resetPassword actions', () => { - it('should create a resetPassword action', () => { - expect(resetPassword.type).toEqual(ActionTypes.RESET_PASSWORD) - }) - - it('should create a resetPasswordSetFormState action', () => { - expect(resetPasswordLoading.type).toEqual(ActionTypes.RESET_PASSWORD_LOADING) - }) -}) diff --git a/packages/marketplace/src/actions/forgot-password.ts b/packages/marketplace/src/actions/forgot-password.ts deleted file mode 100644 index 34464c54d5..0000000000 --- a/packages/marketplace/src/actions/forgot-password.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { actionCreator } from '../utils/actions' -import ActionTypes from '../constants/action-types' - -export const submitEmail = actionCreator(ActionTypes.FORGOT_PASSWORD_SUBMIT_EMAIL) -export const forgotPasswordLoading = actionCreator(ActionTypes.FORGOT_PASSWORD_LOADING) diff --git a/packages/marketplace/src/actions/reset-password.ts b/packages/marketplace/src/actions/reset-password.ts deleted file mode 100644 index 8c157fc81d..0000000000 --- a/packages/marketplace/src/actions/reset-password.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { actionCreator } from '../utils/actions' -import ActionTypes from '../constants/action-types' - -export type ResetPasswordParams = { - email: string - password: string - confirmPassword: string - verificationCode: string -} -export const resetPassword = actionCreator(ActionTypes.RESET_PASSWORD) -export const resetPasswordLoading = actionCreator(ActionTypes.RESET_PASSWORD_LOADING) diff --git a/packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap b/packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap deleted file mode 100644 index d990dda2ac..0000000000 --- a/packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password-form.tsx.snap +++ /dev/null @@ -1,88 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ForgotPasswordForm should match snapshot 1`] = ` -
- - Please enter your email address to reset your password - - - - - - - - - Submit - - - -`; - -exports[`ForgotPasswordForm should match snapshot 2`] = ` -
- - Please enter your email address to reset your password - - - - - - - - - - Submit - - - -`; - -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/packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password.tsx.snap b/packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password.tsx.snap deleted file mode 100644 index 92a7b12841..0000000000 --- a/packages/marketplace/src/components/pages/forgot-password/__tests__/__snapshots__/forgot-password.tsx.snap +++ /dev/null @@ -1,55 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ForgotPassword should match snapshot 1`] = ` -
-
- - Forgot password - -

- Welcome to Reapit Foundations -

- -
-
- Reapit Graphic -
-
-`; - -exports[`ForgotPassword should match snapshot 2`] = ` -
-
- - Forgot password - -

- Welcome to Reapit Foundations -

- -
-
- Reapit Graphic -
-
-`; diff --git a/packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx b/packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx deleted file mode 100644 index f0cd9768e2..0000000000 --- a/packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password-form.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import React from 'react' -import { shallow } from 'enzyme' -import { getMockRouterProps } from '@/utils/mock-helper' -import { mockFormikAction, mockWithFormik } from '@/utils/mock-formik' -import { - ForgotPasswordForm, - mapPropsToValues, - ForgotPasswordValues, - handleSubmitForgotPassword, - ForgotPasswordFormProps, - SuccessForgetPasswordContent, -} from '../forgot-password-form' - -describe('ForgotPasswordForm', () => { - it('should match snapshot', () => { - const mockProps = { - ...mockWithFormik({ email: '1' }), - ...getMockRouterProps({}), - getFieldHelpers: jest.fn(), - } as ForgotPasswordFormProps - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - expect(wrapper.find('[dataTest="email"]')).toHaveLength(1) - }) - - it('should match snapshot', () => { - const mockProps = { - ...mockWithFormik({ email: '1' }), - ...getMockRouterProps({}), - location: { - hash: '', - key: '', - pathname: '', - search: '?isError=1', - state: {}, - }, - getFieldHelpers: jest.fn(), - } as ForgotPasswordFormProps - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - 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: {}, - }, - getFieldHelpers: jest.fn(), - } as ForgotPasswordFormProps - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - }) - - describe('mapPropsToValues', () => { - it('should run correctly', () => { - const result = mapPropsToValues() - expect(result).toEqual({ email: '' }) - }) - }) - - describe('mapPropsToValues', () => { - it('should run correctly', () => { - const result = mapPropsToValues() - expect(result).toEqual({ email: '' }) - }) - }) - - describe('handleSubmitForgotPassword', () => { - it('should call setSubmitting with false', done => { - const mockValues = { - email: 'abc@gmail.com', - } as ForgotPasswordValues - const mockProps = { - ...getMockRouterProps({}), - submitEmail: jest.fn(), - } - const mockFormik = { - ...mockFormikAction, - } - setTimeout(() => { - handleSubmitForgotPassword(mockValues, { ...mockFormik, props: mockProps }) - expect(mockProps.submitEmail).toBeCalled() - done() - }, 1000) - }) - }) -}) - -describe('SuccessForgetPasswordContent', () => { - it('should match snapshot', () => { - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - }) -}) diff --git a/packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password.tsx b/packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password.tsx deleted file mode 100644 index 47b03432b3..0000000000 --- a/packages/marketplace/src/components/pages/forgot-password/__tests__/forgot-password.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import React from 'react' -import { shallow } from 'enzyme' -import { ForgotPassword, mapDispatchToProps, mapStateToProps } from '../forgot-password' -import { getMockRouterProps } from '@/utils/mock-helper' -import { ReduxState } from '@/types/core' - -describe('ForgotPassword', () => { - it('should match snapshot', () => { - const mockProps = { - ...getMockRouterProps({}), - location: { - hash: '', - key: '', - pathname: '', - state: {}, - search: '?isSuccessRequestResetPassword=1', - }, - loading: false, - submitEmail: jest.fn(), - } - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - expect(wrapper.find('[className="pb-8"]')).toHaveLength(1) - expect(wrapper.find('EnhanceForgotPasswordForm')).toHaveLength(1) - }) - - it('should match snapshot', () => { - const mockProps = { - ...getMockRouterProps({}), - location: { - hash: '', - key: '', - pathname: '', - state: {}, - search: '', - }, - loading: true, - submitEmail: jest.fn(), - } - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - expect(wrapper.find('EnhanceForgotPasswordForm')).toHaveLength(0) - }) - describe('mapDispatchToProps', () => { - it('should call dispatch when call submitEmail', () => { - const mockDispatch = jest.fn() - const { submitEmail } = mapDispatchToProps(mockDispatch) - submitEmail('abc@gmail.com') - expect(mockDispatch).toBeCalled() - }) - }) - - describe('mapStateToProps', () => { - it('should return correctly', () => { - const mockState = { - forgotPassword: { - loading: true, - }, - } as ReduxState - const result = mapStateToProps(mockState) - expect(result).toEqual({ loading: true }) - }) - - it('should return undefined', () => { - const mockState = {} as ReduxState - const result = mapStateToProps(mockState) - expect(result).toEqual({ loading: undefined }) - }) - }) -}) diff --git a/packages/marketplace/src/components/pages/forgot-password/forgot-password-form.tsx b/packages/marketplace/src/components/pages/forgot-password/forgot-password-form.tsx deleted file mode 100644 index bffe4c101f..0000000000 --- a/packages/marketplace/src/components/pages/forgot-password/forgot-password-form.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import React from 'react' -import { compose } from 'redux' -import { - FlexContainerResponsive, - GridItem, - FormSubHeading, - Grid, - Input, - Button, - Alert, - Form, - withFormik, - FormikProps, - 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 - -export const ForgotPasswordForm: React.FC = ({ - isSubmitting, - isValidating, - isValid, - 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 - - - - - - {isError && ( - - )} - - - - - ) -} - -export type ForgotPasswordValues = { - email: string -} - -export const mapPropsToValues = (): ForgotPasswordValues => ({ - email: '', -}) - -export const handleSubmitForgotPassword = async ( - values: ForgotPasswordValues, - { props }: FormikBag, -) => { - props.submitEmail(values.email) -} - -export const withForgotPasswordForm = withFormik({ - displayName: 'WithForgotPasswordForm', - mapPropsToValues, - handleSubmit: handleSubmitForgotPassword, -}) - -export type EnhanceForgotPasswordFormProps = { - submitEmail: (email: string) => void -} - -const EnhanceForgotPasswordForm = compose>( - withRouter, - withForgotPasswordForm, -)(ForgotPasswordForm) -EnhanceForgotPasswordForm.displayName = 'EnhanceForgotPasswordForm' - -export default EnhanceForgotPasswordForm diff --git a/packages/marketplace/src/components/pages/forgot-password/forgot-password.tsx b/packages/marketplace/src/components/pages/forgot-password/forgot-password.tsx deleted file mode 100644 index 7cc3758ab3..0000000000 --- a/packages/marketplace/src/components/pages/forgot-password/forgot-password.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import React from 'react' -import { H1, Loader } from '@reapit/elements' -import { compose, Dispatch } from 'redux' -import logoImage from '@/assets/images/reapit-graphic.jpg' -import loginStyles from '@/styles/pages/login.scss?mod' -import EnhanceForgotPasswordForm from './forgot-password-form' -import { connect } from 'react-redux' -import { submitEmail } from '@/actions/forgot-password' -import { ReduxState } from '@/types/core' - -export type ForgotPasswordProps = StateProps & DispatchProps - -export const ForgotPassword: React.FC = ({ submitEmail, loading }) => { - return ( -
-
-

Forgot password

-

Welcome to Reapit Foundations

- {loading ? : } -
-
- Reapit Graphic -
-
- ) -} - -export type DispatchProps = { - submitEmail: (email: string) => void -} - -export const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => { - return { - submitEmail: email => dispatch(submitEmail(email)), - } -} - -export type StateProps = { - loading: boolean -} - -export const mapStateToProps = (state: ReduxState): StateProps => { - return { - loading: state.forgotPassword?.loading, - } -} - -export const withRedux = connect(mapStateToProps, mapDispatchToProps) - -export default compose>(withRedux)(ForgotPassword) diff --git a/packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password-form.tsx.snap b/packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password-form.tsx.snap deleted file mode 100644 index 659dc371b5..0000000000 --- a/packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password-form.tsx.snap +++ /dev/null @@ -1,42 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ResetPasswordForm should match snapshot 1`] = ` - -
- - - - - - - - - - - - - Reset Password - - - - -`; diff --git a/packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password.tsx.snap b/packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password.tsx.snap deleted file mode 100644 index f8a7a2c5eb..0000000000 --- a/packages/marketplace/src/components/pages/reset-password/__tests__/__snapshots__/reset-password.tsx.snap +++ /dev/null @@ -1,27 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ResetPassword should match snapshot 1`] = ` -
-
- - Reset Password - -

- Welcome to Reapit Foundations -

- -
-
- Reapit Graphic -
-
-`; diff --git a/packages/marketplace/src/components/pages/reset-password/__tests__/reset-password-form.tsx b/packages/marketplace/src/components/pages/reset-password/__tests__/reset-password-form.tsx deleted file mode 100644 index 23a627ff8e..0000000000 --- a/packages/marketplace/src/components/pages/reset-password/__tests__/reset-password-form.tsx +++ /dev/null @@ -1,116 +0,0 @@ -import React from 'react' -import { shallow } from 'enzyme' -import { - ResetPasswordFormProps, - ResetPasswordForm, - mapPropsToValues, - ResetPasswordValues, - handleSubmitResetPassword, - mapDispatchToProps, - mapStateToProps, -} from '../reset-password-form' -import { getMockRouterProps } from '@/utils/mock-helper' -import { mockFormikAction } from '@/utils/mock-formik' -import { ReduxState } from '@/types/core' - -describe('ResetPasswordForm', () => { - it('should match snapshot', () => { - const mockProps = { - isSubmitting: false, - isValidating: false, - isValid: true, - } as ResetPasswordFormProps - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - }) - - describe('mapPropsToValues', () => { - it('should run correctly', () => { - const result = mapPropsToValues() - expect(result).toEqual({ - password: '', - confirmPassword: '', - }) - }) - }) - - describe('handleSubmitResetPassword', () => { - it('should not call resetPassword', done => { - const mockValues: ResetPasswordValues = { - password: '456', - confirmPassword: '456', - } - const mockForm = { - ...mockFormikAction, - } - const mockProps = { - resetPassword: jest.fn(), - logout: jest.fn(), - ...getMockRouterProps({}), - } - handleSubmitResetPassword(mockValues, { ...mockForm, props: mockProps }) - setTimeout(() => { - expect(mockProps.resetPassword).not.toBeCalled() - done() - }, 2000) - }) - }) - - describe('handleSubmitResetPassword', () => { - it('should call resetPassword', done => { - const mockValues: ResetPasswordValues = { - password: 'Password1', - confirmPassword: 'Password1', - } - const mockForm = { - ...mockFormikAction, - } - const mockProps = { - resetPassword: jest.fn(), - logout: jest.fn(), - ...getMockRouterProps({}), - location: { - hash: '', - key: '', - pathname: '', - search: '?userName=mockEmail@gmail.com&verificationCode=123', - state: {}, - }, - } - handleSubmitResetPassword(mockValues, { ...mockForm, props: mockProps }) - setTimeout(() => { - expect(mockProps.resetPassword).toBeCalled() - done() - }, 2000) - }) - }) - - describe('mapDispatchToProps', () => { - it('should call dispatch when errorNotification', () => { - const mockDispatch = jest.fn() - const { resetPassword } = mapDispatchToProps(mockDispatch) - resetPassword({ - confirmPassword: 'Password1', - password: 'Password1', - email: 'abc@gmail.com', - verificationCode: '123', - }) - expect(mockDispatch).toBeCalled() - }) - }) - - describe('mapStateToProps', () => { - it('should run correctly', () => { - const mockState = { - resetPassword: { - loading: true, - }, - } as ReduxState - const result = mapStateToProps(mockState) - const output = { - loading: true, - } - expect(result).toEqual(output) - }) - }) -}) diff --git a/packages/marketplace/src/components/pages/reset-password/__tests__/reset-password.tsx b/packages/marketplace/src/components/pages/reset-password/__tests__/reset-password.tsx deleted file mode 100644 index b7e11b7096..0000000000 --- a/packages/marketplace/src/components/pages/reset-password/__tests__/reset-password.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from 'react' -import { shallow } from 'enzyme' -import ResetPassword from '../reset-password' - -describe('ResetPassword', () => { - it('should match snapshot', () => { - const wrapper = shallow() - expect(wrapper).toMatchSnapshot() - }) -}) diff --git a/packages/marketplace/src/components/pages/reset-password/index.tsx b/packages/marketplace/src/components/pages/reset-password/index.tsx deleted file mode 100644 index d0247f9950..0000000000 --- a/packages/marketplace/src/components/pages/reset-password/index.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import ResetPassword from './reset-password' - -export default ResetPassword diff --git a/packages/marketplace/src/components/pages/reset-password/reset-password-form.tsx b/packages/marketplace/src/components/pages/reset-password/reset-password-form.tsx deleted file mode 100644 index 6890e68fe9..0000000000 --- a/packages/marketplace/src/components/pages/reset-password/reset-password-form.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import React from 'react' -import { - FlexContainerBasic, - Grid, - GridItem, - Input, - FlexContainerResponsive, - Button, - Loader, - Form, - withFormik, - FormikProps, - FormikBag, -} from '@reapit/elements' -import { compose, Dispatch } from 'redux' -import { connect } from 'react-redux' -import { resetPassword } from '@/actions/reset-password' -import { ReduxState } from '@/types/core' -import { withRouter, RouteComponentProps } from 'react-router' -import { validate } from '@/utils/form/reset-password' - -export type ResetPasswordFormProps = FormikProps & StateProps & DispatchProps - -export const ResetPasswordForm: React.FC = ({ isValid, loading }) => { - if (loading) { - return - } - return ( - -
- - - - - - - - - - - - - -
-
- ) -} - -export const mapPropsToValues = (): ResetPasswordValues => { - return { - password: '', - confirmPassword: '', - } -} - -export type ResetPasswordValues = { - password: string - confirmPassword: string -} - -export type ResetPasswordParams = { - values: ResetPasswordValues - token: string -} - -export const handleSubmitResetPassword = async ( - values: ResetPasswordValues, - { props }: FormikBag, -) => { - const queryParams = new URLSearchParams(props.location.search) - const email = queryParams.get('userName') - const verificationCode = queryParams.get('verificationCode') - if (email && verificationCode) { - props.resetPassword({ ...values, email, verificationCode }) - } -} - -export const withForm = withFormik({ - displayName: 'ResetPasswordPageWithForm', - validate, - mapPropsToValues: mapPropsToValues, - handleSubmit: handleSubmitResetPassword, -}) - -export type DispatchProps = { - resetPassword: (values: ResetPasswordValues & { email: string; verificationCode: string }) => void -} - -export const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => { - return { - resetPassword: (values: ResetPasswordValues & { email: string; verificationCode: string }) => - dispatch(resetPassword(values)), - } -} - -export type StateProps = { - loading: boolean -} - -export const mapStateToProps = (state: ReduxState): StateProps => { - return { - loading: state.resetPassword?.loading, - } -} - -export const withRedux = connect(mapStateToProps, mapDispatchToProps) - -export type EnhanceResetPasswordFormProps = {} - -export const EnhanceResetPasswordForm = compose>( - withRouter, - withRedux, - withForm, -)(ResetPasswordForm) - -EnhanceResetPasswordForm.displayName = 'EnhanceResetPasswordForm' - -export default EnhanceResetPasswordForm diff --git a/packages/marketplace/src/components/pages/reset-password/reset-password.tsx b/packages/marketplace/src/components/pages/reset-password/reset-password.tsx deleted file mode 100644 index e21b298808..0000000000 --- a/packages/marketplace/src/components/pages/reset-password/reset-password.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react' -import { H1 } from '@reapit/elements' -import loginStyles from '@/styles/pages/login.scss?mod' -import logoImage from '@/assets/images/reapit-graphic.jpg' -import EnhanceResetPasswordForm from './reset-password-form' - -export const ResetPassword: React.FC = () => { - return ( -
-
-

Reset Password

-

Welcome to Reapit Foundations

- -
-
- Reapit Graphic -
-
- ) -} - -export default ResetPassword diff --git a/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap b/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap index 60a191b096..3722cd3ffe 100644 --- a/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap +++ b/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap @@ -37,17 +37,6 @@ exports[`Router should match a snapshot 1`] = ` } render={[Function]} /> - - import('../components/pages/develo const DeveloperHelpPage = React.lazy(() => import('../components/pages/developer-help')) const ClientHelpPage = React.lazy(() => import('../components/pages/client-help')) const AnalyticsPage = React.lazy(() => import('../components/pages/analytics')) -const ResetPassword = React.lazy(() => import('../components/pages/reset-password')) -const ForgotPassword = React.lazy(() => import('../components/pages/forgot-password/forgot-password')) const AdminAppsPage = React.lazy(() => import('../components/pages/admin-apps')) const RegisterConfirm = React.lazy(() => import('../components/pages/register-confirm')) const AdminStats = React.lazy(() => import('../components/pages/admin-stats')) @@ -43,10 +41,7 @@ const Router = () => { } /> - - {/* */} - } /> diff --git a/packages/marketplace/src/core/store.ts b/packages/marketplace/src/core/store.ts index 1a4c4190f0..618ee14338 100644 --- a/packages/marketplace/src/core/store.ts +++ b/packages/marketplace/src/core/store.ts @@ -39,12 +39,8 @@ import adminDevManagementSagas from '../sagas/admin-dev-management' import developerSetStatusSagas from '../sagas/developer-set-status' import revisionDetailSagas from '../sagas/revision-detail' import appDeleteSagas from '../sagas/app-delete' -import forgotPasswordSagas from '../sagas/forgot-password' -import forgotPasswordReducer from '../reducers/forgot-password' import settingSagas from '../sagas/settings' import adminAppsSagas from '../sagas/admin-apps' -import resetPasswordReducer from '../reducers/reset-password' -import resetPasswordSagas from '../sagas/reset-password' import appInstallationsSagas from '../sagas/app-installations' import noticationMessage from '../reducers/notification-message' import adminStatsSaga from '../sagas/admin-stats' @@ -82,9 +78,7 @@ export class Store { appDetailModal, appDelete: appDeleteReducer, appCategories, - forgotPassword: forgotPasswordReducer, settings: settingsReducer, - resetPassword: resetPasswordReducer, installations: appInstallationsReducer, appUsageStats: appUsageStatsReducer, noticationMessage, @@ -107,10 +101,8 @@ export class Store { fork(developerSetStatusSagas), fork(revisionDetailSagas), fork(appDeleteSagas), - fork(forgotPasswordSagas), fork(settingSagas), fork(adminAppsSagas), - fork(resetPasswordSagas), fork(appInstallationsSagas), fork(adminStatsSaga), ]) diff --git a/packages/marketplace/src/reducers/__tests__/forgot-password.ts b/packages/marketplace/src/reducers/__tests__/forgot-password.ts deleted file mode 100644 index 9558e5e077..0000000000 --- a/packages/marketplace/src/reducers/__tests__/forgot-password.ts +++ /dev/null @@ -1,22 +0,0 @@ -import forgotPasswordReducer, { defaultState } from '../forgot-password' -import { ActionType } from '../../types/core' -import ActionTypes from '../../constants/action-types' - -describe('forgot-password reducer', () => { - it('should return default state if action not matched', () => { - const newState = forgotPasswordReducer(undefined, { type: 'UNKNOWN' as ActionType, data: undefined }) - expect(newState).toEqual(defaultState) - }) - - it('should set loading to true when FORGOT_PASSWORD_LOADING action is called', () => { - const newState = forgotPasswordReducer(undefined, { - type: ActionTypes.FORGOT_PASSWORD_LOADING as ActionType, - data: true, - }) - const expected = { - ...defaultState, - loading: true, - } - expect(newState).toEqual(expected) - }) -}) diff --git a/packages/marketplace/src/reducers/__tests__/reset-password.ts b/packages/marketplace/src/reducers/__tests__/reset-password.ts deleted file mode 100644 index 6977b49140..0000000000 --- a/packages/marketplace/src/reducers/__tests__/reset-password.ts +++ /dev/null @@ -1,22 +0,0 @@ -import resetPasswordReducer, { defaultState } from '../reset-password' -import { ActionType } from '../../types/core' -import ActionTypes from '../../constants/action-types' - -describe('resetPassword reducer', () => { - it('should return default state if action not matched', () => { - const newState = resetPasswordReducer(undefined, { type: 'UNKNOWN' as ActionType, data: undefined }) - expect(newState).toEqual(defaultState) - }) - - it('should set formState to test when DEVELOPER_SUBMIT_APP_SET_FORM_STATE action is called with test', () => { - const newState = resetPasswordReducer(undefined, { - type: ActionTypes.RESET_PASSWORD_LOADING as ActionType, - data: true, - }) - const expected = { - ...defaultState, - loading: true, - } - expect(newState).toEqual(expected) - }) -}) diff --git a/packages/marketplace/src/reducers/forgot-password.ts b/packages/marketplace/src/reducers/forgot-password.ts deleted file mode 100644 index f9e8cfbe60..0000000000 --- a/packages/marketplace/src/reducers/forgot-password.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Action } from '../types/core' -import { isType } from '../utils/actions' -import { forgotPasswordLoading } from '@/actions/forgot-password' - -export interface ForgotPasswordState { - loading: boolean -} - -export const defaultState: ForgotPasswordState = { - loading: false, -} - -const forgotPasswordReducer = (state: ForgotPasswordState = defaultState, action: Action): ForgotPasswordState => { - if (isType(action, forgotPasswordLoading)) { - return { - ...state, - loading: action.data, - } - } - - return state -} - -export default forgotPasswordReducer diff --git a/packages/marketplace/src/reducers/reset-password.ts b/packages/marketplace/src/reducers/reset-password.ts deleted file mode 100644 index 7a492601ea..0000000000 --- a/packages/marketplace/src/reducers/reset-password.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Action } from '../types/core' -import { isType } from '../utils/actions' -import { resetPasswordLoading } from '@/actions/reset-password' - -export interface ResetPasswordState { - loading: boolean -} - -export const defaultState: ResetPasswordState = { - loading: false, -} - -const resetPasswordReducer = ( - state: ResetPasswordState | undefined = defaultState, - action: Action, -): ResetPasswordState => { - if (isType(action, resetPasswordLoading)) { - return { - ...state, - loading: action.data, - } - } - - return state -} - -export default resetPasswordReducer diff --git a/packages/marketplace/src/sagas/__tests__/forgot-password.ts b/packages/marketplace/src/sagas/__tests__/forgot-password.ts deleted file mode 100644 index ec8b367c64..0000000000 --- a/packages/marketplace/src/sagas/__tests__/forgot-password.ts +++ /dev/null @@ -1,70 +0,0 @@ -import forgotPasswordSagas, { requestForgotPasswordListen, requestForgotPassword } from '../forgot-password' -import ActionTypes from '@/constants/action-types' -import { put, takeLatest, all, fork, call } from '@redux-saga/core/effects' -import { Action } from '@/types/core' -import { cloneableGenerator } from '@redux-saga/testing-utils' -import { forgotPasswordLoading } from '@/actions/forgot-password' -import { history } from '@/core/router' -import Routes from '@/constants/routes' -import { resetPassword } from '@reapit/cognito-auth' - -jest.mock('@reapit/elements') -jest.mock('@reapit/cognito-auth') -jest.mock('../../core/router', () => ({ - history: { - push: jest.fn(), - }, -})) - -describe('requestForgotPassword', () => { - window.reapit.config.cognitoClientId = 'cognitoClientId' - const gen = cloneableGenerator(requestForgotPassword)({ data: 'abc@gmail.com' }) - expect(gen.next().value).toEqual(put(forgotPasswordLoading(true))) - expect(gen.next().value).toEqual( - call(resetPassword, { userName: 'abc@gmail.com', cognitoClientId: 'cognitoClientId' }), - ) - - it('should call API success', () => { - const clone = gen.clone() - 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) - }) - - it('dont do anything, set loading to false if result not correct', () => { - const clone = gen.clone() - expect(clone.next({ CodeDeliveryDetails: undefined }).value).toEqual(put(forgotPasswordLoading(false))) - expect(clone.next().done).toEqual(true) - }) - - it('should call API failed', () => { - const clone = gen.clone() - // @ts-ignore - expect(clone.throw(new Error('Client id is not exists')).value).toEqual( - history.push(`${Routes.FORGOT_PASSWORD}?isError=1`), - ) - expect(clone.next().value).toEqual(put(forgotPasswordLoading(false))) - expect(clone.next().done).toEqual(true) - }) -}) - -describe('forgot-password thunks', () => { - describe('requestForgotPasswordListen', () => { - it('should request data when called', () => { - const gen = requestForgotPasswordListen() - expect(gen.next().value).toEqual( - takeLatest>(ActionTypes.FORGOT_PASSWORD_SUBMIT_EMAIL, requestForgotPassword), - ) - expect(gen.next().done).toBe(true) - }) - }) - - describe('forgotPasswordSagas', () => { - it('should listen request data', () => { - const gen = forgotPasswordSagas() - - expect(gen.next().value).toEqual(all([fork(requestForgotPasswordListen)])) - expect(gen.next().done).toBe(true) - }) - }) -}) diff --git a/packages/marketplace/src/sagas/__tests__/reset-password.ts b/packages/marketplace/src/sagas/__tests__/reset-password.ts deleted file mode 100644 index b6ad4494ee..0000000000 --- a/packages/marketplace/src/sagas/__tests__/reset-password.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { cloneableGenerator } from '@redux-saga/testing-utils' -import ActionTypes from '@/constants/action-types' -import { put, fork, all, call, takeLatest } from '@redux-saga/core/effects' -import { Action } from '@/types/core' -import { ResetPasswordParams, resetPasswordLoading } from '@/actions/reset-password' -import { history } from '@/core/router' -import resetPasswordSagas, { developerResetPassword, developerResetPasswordListen } from '../reset-password' -import Routes from '@/constants/routes' -import { errorThrownServer } from '@/actions/error' -import errorMessages from '@/constants/error-messages' -import { confirmPassword } from '@reapit/cognito-auth' - -jest.mock('@reapit/cognito-auth') - -describe('developerResetPassword', () => { - window.reapit.config.cognitoClientId = 'cognitoClientId' - const gen = cloneableGenerator(developerResetPassword)({ - type: 'RESET_PASSWORD', - data: { password: '123', email: '123@gmail.com', verificationCode: '123', confirmPassword: '123' }, - }) - expect(gen.next().value).toEqual(put(resetPasswordLoading(true))) - - it('should call API success', () => { - const clone = gen.clone() - const body = { - newPassword: '123', - userName: '123@gmail.com', - verificationCode: '123', - cognitoClientId: 'cognitoClientId', - } - expect(clone.next().value).toEqual(call(confirmPassword, body)) - expect(clone.next('SUCCESS').value).toEqual(history.push(`${Routes.DEVELOPER_LOGIN}?isChangePasswordSuccess=1`)) - expect(clone.next().value).toEqual(put(resetPasswordLoading(false))) - expect(clone.next().done).toEqual(true) - }) - - it('should do nothing and set loading to false when message is not SUCCESS', () => { - const clone = gen.clone() - const body = { - newPassword: '123', - userName: '123@gmail.com', - verificationCode: '123', - cognitoClientId: 'cognitoClientId', - } - expect(clone.next().value).toEqual(call(confirmPassword, body)) - expect(clone.next(undefined).value).toEqual(put(resetPasswordLoading(false))) - expect(clone.next().done).toEqual(true) - }) - - it('should call API fail', () => { - const clone = gen.clone() - const body = { - newPassword: '123', - userName: '123@gmail.com', - verificationCode: '123', - cognitoClientId: 'cognitoClientId', - } - expect(clone.next().value).toEqual(call(confirmPassword, body)) - // @ts-ignore - expect(clone.throw(new Error('123')).value).toEqual( - put( - errorThrownServer({ - type: 'SERVER', - message: errorMessages.DEFAULT_SERVER_ERROR, - }), - ), - ) - expect(clone.next().value).toEqual(put(resetPasswordLoading(false))) - expect(clone.next().done).toEqual(true) - }) -}) - -describe('reset-password thunks', () => { - describe('developerResetPasswordListen', () => { - it('should submit data when called', () => { - const gen = developerResetPasswordListen() - expect(gen.next().value).toEqual( - takeLatest>(ActionTypes.RESET_PASSWORD, developerResetPassword), - ) - expect(gen.next().done).toBe(true) - }) - }) - - describe('resetPasswordSagas', () => { - it('should listen saga', () => { - const gen = resetPasswordSagas() - - expect(gen.next().value).toEqual(all([fork(developerResetPasswordListen)])) - expect(gen.next().done).toBe(true) - }) - }) -}) diff --git a/packages/marketplace/src/sagas/forgot-password.ts b/packages/marketplace/src/sagas/forgot-password.ts deleted file mode 100644 index 87ede10a1c..0000000000 --- a/packages/marketplace/src/sagas/forgot-password.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { put, fork, takeLatest, all, call } from '@redux-saga/core/effects' -import ActionTypes from '../constants/action-types' -import { history } from '../core/router' -import Routes from '@/constants/routes' -import { Action } from '@/types/core' -import { forgotPasswordLoading } from '@/actions/forgot-password' -import { resetPassword } from '@reapit/cognito-auth' -import { logger } from 'logger' - -export const requestForgotPassword = function*({ data: email }) { - yield put(forgotPasswordLoading(true)) - try { - const response = yield call(resetPassword, { - userName: email, - cognitoClientId: window.reapit.config.cognitoClientId, - }) - if (response.CodeDeliveryDetails) { - yield history.push(`${Routes.FORGOT_PASSWORD}?isSuccess=1`) - } - } catch (error) { - logger(error) - yield history.push(`${Routes.FORGOT_PASSWORD}?isError=1`) - } finally { - yield put(forgotPasswordLoading(false)) - } -} - -export const requestForgotPasswordListen = function*() { - yield takeLatest>(ActionTypes.FORGOT_PASSWORD_SUBMIT_EMAIL, requestForgotPassword) -} - -const forgotPasswordSagas = function*() { - yield all([fork(requestForgotPasswordListen)]) -} - -export default forgotPasswordSagas diff --git a/packages/marketplace/src/sagas/reset-password.ts b/packages/marketplace/src/sagas/reset-password.ts deleted file mode 100644 index a6fbca3b77..0000000000 --- a/packages/marketplace/src/sagas/reset-password.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { put, fork, all, call, takeLatest } from '@redux-saga/core/effects' -import { resetPasswordLoading, ResetPasswordParams } from '@/actions/reset-password' -import { Action } from '@/types/core' -import ActionTypes from '@/constants/action-types' -import errorMessages from '@/constants/error-messages' -import { errorThrownServer } from '@/actions/error' -import Routes from '@/constants/routes' -import { history } from '@/core/router' -import { confirmPassword } from '@reapit/cognito-auth' -import { logger } from 'logger' - -export const developerResetPassword = function*({ data }: Action) { - yield put(resetPasswordLoading(true)) - try { - const response = yield call(confirmPassword, { - newPassword: data.password, - userName: data.email, - verificationCode: data.verificationCode, - cognitoClientId: window.reapit.config.cognitoClientId, - }) - const isSuccess = response === 'SUCCESS' - if (isSuccess) { - yield history.push(`${Routes.DEVELOPER_LOGIN}?isChangePasswordSuccess=1`) - } - } catch (error) { - logger(error) - yield put( - errorThrownServer({ - type: 'SERVER', - message: errorMessages.DEFAULT_SERVER_ERROR, - }), - ) - } finally { - yield put(resetPasswordLoading(false)) - } -} - -export const developerResetPasswordListen = function*() { - yield takeLatest>(ActionTypes.RESET_PASSWORD, developerResetPassword) -} - -const resetPasswordSagas = function*() { - yield all([fork(developerResetPasswordListen)]) -} - -export default resetPasswordSagas diff --git a/packages/marketplace/src/types/core.ts b/packages/marketplace/src/types/core.ts index 8ac6dbdd38..bf26d1ce57 100644 --- a/packages/marketplace/src/types/core.ts +++ b/packages/marketplace/src/types/core.ts @@ -14,10 +14,8 @@ import { AdminApprovalsState } from '@/reducers/admin-approvals' import { RevisionDetailState } from '@/reducers/revision-detail' import { AppDetailModalState } from '@/reducers/app-detail-modal' import { AppCategoriesState } from '@/reducers/app-categories' -import { ForgotPasswordState } from '@/reducers/forgot-password' import { SettingsState } from '@/reducers/settings' import { AdminAppsState } from '@/reducers/admin-apps' -import { ResetPasswordState } from '@/reducers/reset-password' import { AppInstallationsState } from '@/reducers/app-installations' import { AppUsageStatsState } from '@/reducers/app-usage-stats' import { NotificationMessageState } from '@/reducers/notification-message' @@ -76,9 +74,7 @@ export interface ReduxState { appDetailModal: AppDetailModalState appDelete: RequestState appCategories: AppCategoriesState - forgotPassword: ForgotPasswordState settings: SettingsState - resetPassword: ResetPasswordState installations: AppInstallationsState appUsageStats: AppUsageStatsState noticationMessage: NotificationMessageState diff --git a/packages/marketplace/src/utils/form/__tests__/reset-password.ts b/packages/marketplace/src/utils/form/__tests__/reset-password.ts deleted file mode 100644 index 706d6d5ccc..0000000000 --- a/packages/marketplace/src/utils/form/__tests__/reset-password.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { validate } from '../reset-password' -import { ResetPasswordValues } from '@/components/pages/reset-password/reset-password-form' -import errorMessages from '@/constants/error-messages' - -describe('changePasswordValidation', () => { - it('validate invalid password', () => { - const input: ResetPasswordValues = { - password: 'newInvalidPassoword', - confirmPassword: 'newInvalidPassoword', - } - expect(validate(input)).toEqual({ - password: errorMessages.FIELD_INVALID_PASSWORD, - }) - }) - - it('validate passwords are not match', () => { - const input: ResetPasswordValues = { - password: 'Password1', - confirmPassword: 'Password2', - } - expect(validate(input)).toEqual({ - confirmPassword: 'Passwords do not match.', - }) - }) - - it('return empty object it everything is valid', () => { - const input: ResetPasswordValues = { - password: 'Password1', - confirmPassword: 'Password1', - } - expect(validate(input)).toEqual({}) - }) -}) diff --git a/packages/marketplace/src/utils/form/reset-password.ts b/packages/marketplace/src/utils/form/reset-password.ts deleted file mode 100644 index 4541a02b1e..0000000000 --- a/packages/marketplace/src/utils/form/reset-password.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { ResetPasswordValues } from '@/components/pages/reset-password/reset-password-form' -import { validatePassword } from '@reapit/elements' - -export type ResetPasswordFormErrorKeys = keyof ResetPasswordValues - -export const validate = (values: ResetPasswordValues) => { - let errors = validatePassword({ - values, - currentErrors: {}, - keys: ['password'], - }) - - if (values.password !== values.confirmPassword) { - errors.confirmPassword = 'Passwords do not match.' - } - - return errors -}