-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user_password_reset): add password reset feature
- Loading branch information
Showing
20 changed files
with
393 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/components/ForgotPasswordForm/ForgotPasswordForm.container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @file ForgotPasswordForm.container.js | ||
* Exports a redux-connected ForgotPasswordForm component. | ||
*/ | ||
|
||
import { connect } from 'react-redux'; | ||
|
||
import ForgotPasswordForm from './ForgotPasswordForm'; | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
dispatch | ||
}); | ||
|
||
const mapState = ({ user }) => ({ | ||
user | ||
}); | ||
|
||
export default connect(mapState, mapDispatchToProps)(ForgotPasswordForm); |
117 changes: 117 additions & 0 deletions
117
src/components/ForgotPasswordForm/ForgotPasswordForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* @file ForgotPasswordForm.js | ||
* Exports a component that allows users to reset their EditVR account password. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { TextField, Button, withStyles } from '@material-ui/core'; | ||
import { withFormik } from 'formik'; | ||
import { string, object } from 'yup'; | ||
|
||
import { Message } from '../'; | ||
import ForgotPasswordFormStyles from './ForgotPasswordForm.style'; | ||
import { | ||
USER_RESET_PASSWORD, | ||
FORM_BUTTON_RESET_PASSWORD, | ||
ERROR_API_USER_EMAIL_NOT_FOUND | ||
} from '../../constants'; | ||
|
||
const ForgotPasswordForm = ({ | ||
classes, | ||
user: { error }, | ||
errors, | ||
touched, | ||
isSubmitting, | ||
handleSubmit, | ||
handleChange, | ||
handleBlur | ||
}) => ( | ||
<form onSubmit={handleSubmit}> | ||
{error && <Message type="error">{error}</Message>} | ||
<TextField | ||
required | ||
id="email" | ||
label="Email" | ||
type="email" | ||
className={classes.textField} | ||
onChange={handleChange} | ||
onBlur={handleBlur} | ||
error={!!errors.email && touched.email} | ||
disabled={isSubmitting} | ||
helperText={ | ||
errors.email | ||
? errors.email | ||
: 'Enter the email address for your account.' | ||
} | ||
/> | ||
<Button | ||
variant="raised" | ||
color="primary" | ||
type="submit" | ||
className={classes.button} | ||
> | ||
{`${FORM_BUTTON_RESET_PASSWORD}`} | ||
</Button> | ||
</form> | ||
); | ||
|
||
ForgotPasswordForm.propTypes = { | ||
classes: PropTypes.shape({ | ||
textField: PropTypes.string.isRequired, | ||
button: PropTypes.string.isRequired | ||
}).isRequired, | ||
user: PropTypes.shape({ | ||
error: PropTypes.string | ||
}), | ||
handleSubmit: PropTypes.func.isRequired, | ||
handleChange: PropTypes.func.isRequired, | ||
handleBlur: PropTypes.func.isRequired, | ||
isSubmitting: PropTypes.bool, | ||
errors: PropTypes.shape({ | ||
email: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]) | ||
}).isRequired, | ||
touched: PropTypes.shape({ | ||
email: PropTypes.bool | ||
}).isRequired | ||
}; | ||
|
||
ForgotPasswordForm.defaultProps = { | ||
isSubmitting: false, | ||
user: { | ||
error: null | ||
} | ||
}; | ||
|
||
const FormikForgotPasswordForm = withFormik({ | ||
displayName: 'ForgotPasswordForm', | ||
enableReinitialize: true, | ||
validationSchema: object().shape({ | ||
email: string() | ||
.email() | ||
.required() | ||
.min(3) | ||
.max(100) | ||
}), | ||
handleSubmit: (values, { props, setSubmitting, setErrors }) => { | ||
const { dispatch } = props; | ||
const { email } = values; | ||
dispatch({ | ||
type: USER_RESET_PASSWORD, | ||
email, | ||
successHandler: () => { | ||
// After sending email, tell the user? | ||
setSubmitting(false); | ||
}, | ||
errorHandler: error => { | ||
const message = error.toString(); | ||
if (message.includes(ERROR_API_USER_EMAIL_NOT_FOUND)) { | ||
setErrors({ email: 'Account matching email not found.' }); | ||
} | ||
setSubmitting(false); | ||
} | ||
}); | ||
} | ||
})(ForgotPasswordForm); | ||
|
||
export default withStyles(ForgotPasswordFormStyles)(FormikForgotPasswordForm); |
15 changes: 15 additions & 0 deletions
15
src/components/ForgotPasswordForm/ForgotPasswordForm.style.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @file ForgotPasswordForm.style.js | ||
* Exports ForgotPasswordForm component styles. | ||
*/ | ||
|
||
export default theme => ({ | ||
textField: { | ||
width: '100%', | ||
marginTop: `${theme.spacing.unit * 2}px` | ||
}, | ||
button: { | ||
marginTop: `${theme.spacing.unit * 3}px`, | ||
marginRight: theme.spacing.unit | ||
} | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/components/ForgotPasswordForm/ForgotPasswordForm.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @file ForgotPasswordForm.test.js | ||
* Contains tests for ForgotPasswordForm.js. | ||
*/ | ||
|
||
import React from 'react'; | ||
import configureStore from 'redux-mock-store'; | ||
import renderer from 'react-test-renderer'; | ||
import ForgotPasswordForm from './ForgotPasswordForm.container'; | ||
|
||
describe('<ForgotPasswordForm />', () => { | ||
it('Matches its snapshot', () => { | ||
const store = configureStore()({ | ||
user: { | ||
error: null | ||
} | ||
}); | ||
|
||
expect( | ||
renderer.create(<ForgotPasswordForm store={store} />).toJSON() | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.