|
1 |
| -import PropTypes from 'prop-types'; |
2 | 1 | import React from 'react';
|
3 |
| -import { withTranslation } from 'react-i18next'; |
4 |
| -import { domOnlyProps } from '../../../utils/reduxFormUtils'; |
| 2 | +import { useTranslation } from 'react-i18next'; |
| 3 | +import { Form, Field } from 'react-final-form'; |
| 4 | +import { useDispatch, useSelector } from 'react-redux'; |
| 5 | +import { validateResetPassword } from '../../../utils/reduxFormUtils'; |
| 6 | +import { initiateResetPassword } from '../actions'; |
5 | 7 | import Button from '../../../common/Button';
|
6 | 8 |
|
7 | 9 | function ResetPasswordForm(props) {
|
8 |
| - const { |
9 |
| - fields: { email }, handleSubmit, submitting, invalid, pristine, t |
10 |
| - } = props; |
| 10 | + const { t } = useTranslation(); |
| 11 | + const resetPasswordInitiate = useSelector(state => state.user.resetPasswordInitiate); |
| 12 | + const dispatch = useDispatch(); |
| 13 | + |
| 14 | + function submitInitiateResetPassword() { |
| 15 | + dispatch(initiateResetPassword()); |
| 16 | + } |
| 17 | + |
11 | 18 | return (
|
12 |
| - <form |
13 |
| - className="form" |
14 |
| - onSubmit={handleSubmit(props.initiateResetPassword.bind(this))} |
| 19 | + <Form |
| 20 | + fields={['email']} |
| 21 | + validate={validateResetPassword} |
| 22 | + onSubmit={submitInitiateResetPassword} |
15 | 23 | >
|
16 |
| - <p className="form__field"> |
17 |
| - <label htmlFor="email" className="form__label">{t('ResetPasswordForm.Email')}</label> |
18 |
| - <input |
19 |
| - className="form__input" |
20 |
| - aria-label={t('ResetPasswordForm.EmailARIA')} |
21 |
| - type="text" |
22 |
| - id="email" |
23 |
| - {...domOnlyProps(email)} |
24 |
| - /> |
25 |
| - {email.touched && email.error && ( |
26 |
| - <span className="form-error">{email.error}</span> |
27 |
| - )} |
28 |
| - </p> |
29 |
| - <Button |
30 |
| - type="submit" |
31 |
| - disabled={submitting || invalid || pristine || props.user.resetPasswordInitiate} |
32 |
| - >{t('ResetPasswordForm.Submit')} |
33 |
| - </Button> |
34 |
| - </form> |
| 24 | + {({ |
| 25 | + handleSubmit, submitting, pristine, invalid |
| 26 | + }) => ( |
| 27 | + <form |
| 28 | + className="form" |
| 29 | + onSubmit={handleSubmit} |
| 30 | + > |
| 31 | + <Field name="email"> |
| 32 | + {field => ( |
| 33 | + <p className="form__field"> |
| 34 | + <label htmlFor="email" className="form__label">{t('ResetPasswordForm.Email')}</label> |
| 35 | + <input |
| 36 | + className="form__input" |
| 37 | + aria-label={t('ResetPasswordForm.EmailARIA')} |
| 38 | + type="text" |
| 39 | + id="email" |
| 40 | + {...field.input} |
| 41 | + /> |
| 42 | + {field.meta.touched && field.meta.error && ( |
| 43 | + <span className="form-error">{field.meta.error}</span> |
| 44 | + )} |
| 45 | + </p> |
| 46 | + )} |
| 47 | + </Field> |
| 48 | + <Button |
| 49 | + type="submit" |
| 50 | + disabled={submitting || invalid || pristine || resetPasswordInitiate} |
| 51 | + >{t('ResetPasswordForm.Submit')} |
| 52 | + </Button> |
| 53 | + </form> |
| 54 | + )} |
| 55 | + </Form> |
35 | 56 | );
|
36 | 57 | }
|
37 | 58 |
|
38 |
| -ResetPasswordForm.propTypes = { |
39 |
| - fields: PropTypes.shape({ |
40 |
| - email: PropTypes.objectOf(PropTypes.shape()).isRequired |
41 |
| - }).isRequired, |
42 |
| - handleSubmit: PropTypes.func.isRequired, |
43 |
| - initiateResetPassword: PropTypes.func.isRequired, |
44 |
| - submitting: PropTypes.bool, |
45 |
| - invalid: PropTypes.bool, |
46 |
| - pristine: PropTypes.bool, |
47 |
| - user: PropTypes.shape({ |
48 |
| - resetPasswordInitiate: PropTypes.bool |
49 |
| - }).isRequired, |
50 |
| - t: PropTypes.func.isRequired |
51 |
| -}; |
52 |
| - |
53 |
| -ResetPasswordForm.defaultProps = { |
54 |
| - submitting: false, |
55 |
| - pristine: true, |
56 |
| - invalid: false, |
57 |
| -}; |
58 |
| - |
59 |
| -export default withTranslation()(ResetPasswordForm); |
| 59 | +export default ResetPasswordForm; |
0 commit comments