Skip to content

Commit 9c6f5bb

Browse files
committed
Migrate ResetPasswordForm to final-form
1 parent 6f5fff5 commit 9c6f5bb

File tree

3 files changed

+64
-90
lines changed

3 files changed

+64
-90
lines changed

client/modules/IDE/actions/files.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import objectID from 'bson-objectid';
22
import blobUtil from 'blob-util';
3-
import { reset } from 'redux-form';
43
import apiClient from '../../../utils/apiClient';
54
import * as ActionTypes from '../../../constants';
65
import { setUnsavedChanges, closeNewFolderModal, closeNewFileModal } from './ide';
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
import PropTypes from 'prop-types';
21
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';
57
import Button from '../../../common/Button';
68

79
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+
1118
return (
12-
<form
13-
className="form"
14-
onSubmit={handleSubmit(props.initiateResetPassword.bind(this))}
19+
<Form
20+
fields={['email']}
21+
validate={validateResetPassword}
22+
onSubmit={submitInitiateResetPassword}
1523
>
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>
3556
);
3657
}
3758

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;
Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
2-
import PropTypes from 'prop-types';
31
import React from 'react';
42
import { Link } from 'react-router';
53
import classNames from 'classnames';
6-
import { bindActionCreators } from 'redux';
7-
import { reduxForm } from 'redux-form';
4+
import { useSelector } from 'react-redux';
85
import { Helmet } from 'react-helmet';
9-
import { withTranslation } from 'react-i18next';
10-
import * as UserActions from '../actions';
6+
import { useTranslation } from 'react-i18next';
117
import ResetPasswordForm from '../components/ResetPasswordForm';
12-
import { validateResetPassword } from '../../../utils/reduxFormUtils';
138
import Nav from '../../../components/Nav';
149

15-
function ResetPasswordView(props) {
10+
function ResetPasswordView() {
11+
const { t } = useTranslation();
12+
const resetPasswordInitiate = useSelector(state => state.user.resetPasswordInitiate);
1613
const resetPasswordClass = classNames({
1714
'reset-password': true,
18-
'reset-password--submitted': props.user.resetPasswordInitiate,
15+
'reset-password--submitted': resetPasswordInitiate,
1916
'form-container': true,
2017
'user': true
2118
});
@@ -24,45 +21,23 @@ function ResetPasswordView(props) {
2421
<Nav layout="dashboard" />
2522
<div className={resetPasswordClass}>
2623
<Helmet>
27-
<title>{props.t('ResetPasswordView.Title')}</title>
24+
<title>{t('ResetPasswordView.Title')}</title>
2825
</Helmet>
2926
<div className="form-container__content">
30-
<h2 className="form-container__title">{props.t('ResetPasswordView.Reset')}</h2>
31-
<ResetPasswordForm {...props} />
27+
<h2 className="form-container__title">{t('ResetPasswordView.Reset')}</h2>
28+
<ResetPasswordForm />
3229
<p className="reset-password__submitted">
33-
{props.t('ResetPasswordView.Submitted')}
30+
{t('ResetPasswordView.Submitted')}
3431
</p>
3532
<p className="form__navigation-options">
36-
<Link className="form__login-button" to="/login">{props.t('ResetPasswordView.Login')}</Link>
37-
&nbsp;{props.t('ResetPasswordView.LoginOr')}&nbsp;
38-
<Link className="form__signup-button" to="/signup">{props.t('ResetPasswordView.SignUp')}</Link>
33+
<Link className="form__login-button" to="/login">{t('ResetPasswordView.Login')}</Link>
34+
&nbsp;{t('ResetPasswordView.LoginOr')}&nbsp;
35+
<Link className="form__signup-button" to="/signup">{t('ResetPasswordView.SignUp')}</Link>
3936
</p>
4037
</div>
4138
</div>
4239
</div>
4340
);
4441
}
4542

46-
ResetPasswordView.propTypes = {
47-
resetPasswordReset: PropTypes.func.isRequired,
48-
user: PropTypes.shape({
49-
resetPasswordInitiate: PropTypes.bool
50-
}).isRequired,
51-
t: PropTypes.func.isRequired
52-
};
53-
54-
function mapStateToProps(state) {
55-
return {
56-
user: state.user
57-
};
58-
}
59-
60-
function mapDispatchToProps(dispatch) {
61-
return bindActionCreators(UserActions, dispatch);
62-
}
63-
64-
export default withTranslation()(reduxForm({
65-
form: 'reset-password',
66-
fields: ['email'],
67-
validate: validateResetPassword
68-
}, mapStateToProps, mapDispatchToProps)(ResetPasswordView));
43+
export default ResetPasswordView;

0 commit comments

Comments
 (0)