From a70ba337f759e0b2377c72cdfccfa553fa8ff983 Mon Sep 17 00:00:00 2001 From: Martin Krulis Date: Tue, 16 Jan 2018 23:16:57 +0100 Subject: [PATCH] Update of user edit form to correctly reflect situation when local password is empty and should not be required. Also some minor improvements in the form were made incidentally. --- .../EditUserProfileForm.js | 68 +++++++++++++------ src/pages/EditUser/EditUser.js | 7 +- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/components/forms/EditUserProfileForm/EditUserProfileForm.js b/src/components/forms/EditUserProfileForm/EditUserProfileForm.js index 5f495f725..284632803 100644 --- a/src/components/forms/EditUserProfileForm/EditUserProfileForm.js +++ b/src/components/forms/EditUserProfileForm/EditUserProfileForm.js @@ -13,14 +13,16 @@ import { TextField, PasswordField, PasswordStrength } from '../Fields'; const EditUserProfileForm = ({ submitting, handleSubmit, - anyTouched, + dirty, submitFailed = false, submitSucceeded = false, asyncValidate, pristine, asyncValidating, invalid, - allowChangePassword + allowChangePassword, + emptyLocalPassword, + reset }) => handleSubmit(data).then(() => reset())} submitting={submitting} - dirty={anyTouched} + dirty={dirty} + invalid={invalid} hasSucceeded={submitSucceeded} hasFailed={submitFailed} asyncValidating={asyncValidating} - invalid={pristine || invalid} tabIndex={9} messages={{ submit: ( @@ -154,18 +156,33 @@ const EditUserProfileForm = ({ />

- - } - /> + {emptyLocalPassword + ?
+

+ +

+

+ +

+
+ : + } + />} - new Promise((resolve, reject) => +const asyncValidate = ({ email, password = '' }, dispatch) => { + if (password === '') { + dispatch(change('edit-user-profile', 'passwordStrength', null)); + return Promise.resolve(); + } + + return new Promise((resolve, reject) => dispatch(validateRegistrationData(email, password)) .then(res => res.value) .then(({ usernameIsFree, passwordScore }) => { @@ -327,7 +351,7 @@ const asyncValidate = ({ email, password = '' }, dispatch) => .then(resolve()) .catch(errors => reject(errors)) ); - +}; export default reduxForm({ form: 'edit-user-profile', validate, diff --git a/src/pages/EditUser/EditUser.js b/src/pages/EditUser/EditUser.js index 7923bc329..5ce275632 100644 --- a/src/pages/EditUser/EditUser.js +++ b/src/pages/EditUser/EditUser.js @@ -81,8 +81,13 @@ class EditUser extends Component {