From 78996abee68e34ced964df226032a2f9eb2467ec Mon Sep 17 00:00:00 2001
From: Anca Ursachi <anca.ursachi@thinslices.com>
Date: Tue, 4 Dec 2018 11:51:09 +0200
Subject: [PATCH] fix(reviewerinviteDecision): After HE invite reviewer he can
 confirm his account with the new passwo

---
 Automation/src/test/java/Utils.java           |  2 +-
 .../src/helpers/formValidators.js             |  8 ++---
 .../SignUp/ReviewerInviteDecision.js          | 32 +++----------------
 .../src/components/SignUp/utils.js            | 11 +++++--
 4 files changed, 18 insertions(+), 35 deletions(-)

diff --git a/Automation/src/test/java/Utils.java b/Automation/src/test/java/Utils.java
index 149e3ef2a..74b8cb314 100644
--- a/Automation/src/test/java/Utils.java
+++ b/Automation/src/test/java/Utils.java
@@ -81,7 +81,7 @@ public class Utils {
 
         driver.findElement(By.name("email")).sendKeys(email);
         driver.findElement(By.name("password")).sendKeys(password);
-        driver.findElement(By.name("confirmPassword")).sendKeys(password);
+        driver.findElement(By.name("confirmNewPassword")).sendKeys(password);
 
         driver.findElement(By.xpath(".//button[contains(text(),'"+"CONFIRM"+"')]")).click();
 
diff --git a/packages/component-faraday-ui/src/helpers/formValidators.js b/packages/component-faraday-ui/src/helpers/formValidators.js
index 300713919..b3a6f6a56 100644
--- a/packages/component-faraday-ui/src/helpers/formValidators.js
+++ b/packages/component-faraday-ui/src/helpers/formValidators.js
@@ -10,10 +10,10 @@ export const passwordValidator = values => {
   if (!values.password) {
     errors.password = 'Required'
   }
-  if (!values.confirmPassword) {
-    errors.confirmPassword = 'Required'
-  } else if (values.confirmPassword !== values.password) {
-    errors.confirmPassword = "Passwords don't match."
+  if (!values.confirmNewPassword) {
+    errors.confirmNewPassword = 'Required'
+  } else if (values.confirmNewPassword !== values.password) {
+    errors.confirmNewPassword = "Passwords don't match."
   }
 
   return errors
diff --git a/packages/components-faraday/src/components/SignUp/ReviewerInviteDecision.js b/packages/components-faraday/src/components/SignUp/ReviewerInviteDecision.js
index a7c1cbaea..5f11176ce 100644
--- a/packages/components-faraday/src/components/SignUp/ReviewerInviteDecision.js
+++ b/packages/components-faraday/src/components/SignUp/ReviewerInviteDecision.js
@@ -1,15 +1,13 @@
 import React from 'react'
 import { connect } from 'react-redux'
 import { reduxForm } from 'redux-form'
-import { required, minChars } from 'xpub-validators'
+// import { required, minChars } from 'xpub-validators'
 import { compose, withState, lifecycle } from 'recompose'
 import { loginUser } from 'pubsweet-component-login/actions'
-import { Button, ValidatedField, H2, TextField, Spinner } from '@pubsweet/ui'
+import { Button, H2, Spinner } from '@pubsweet/ui'
 import {
   Row,
-  Item,
   Text,
-  Label,
   ShadowedBox,
   handleError,
   withFetching,
@@ -18,13 +16,11 @@ import {
 import { redirectToError } from '../utils'
 import { passwordValidator } from '../../../../component-faraday-ui/src/Utils'
 import { reviewerDecision, setReviewerPassword } from '../../redux/reviewers'
+import PasswordValidation from '../../../../component-faraday-ui/src/PasswordValidation'
 
 const agreeText = `You have been invited to review a manuscript on the Hindawi platform. Please set a password and proceed to the manuscript.`
 const declineText = `You have decline to work on a manuscript.`
 
-const PasswordField = input => <TextField {...input} type="password" />
-const min8Chars = minChars(8)
-
 const ReviewerInviteDecision = ({
   agree,
   error,
@@ -44,27 +40,7 @@ const ReviewerInviteDecision = ({
       <Text align="center">{agree === 'true' ? agreeText : declineText}</Text>
     </Row>
 
-    <Row mt={2}>
-      <Item vertical>
-        <Label required>Password</Label>
-        <ValidatedField
-          component={PasswordField}
-          name="password"
-          validate={[required, min8Chars]}
-        />
-      </Item>
-    </Row>
-
-    <Row mt={2}>
-      <Item vertical>
-        <Label required>Confirm password</Label>
-        <ValidatedField
-          component={PasswordField}
-          name="confirmPassword"
-          validate={[required]}
-        />
-      </Item>
-    </Row>
+    <PasswordValidation formLabel="Password" formName="invite-reviewer" />
 
     {fetchingError && (
       <Row mt={2}>
diff --git a/packages/components-faraday/src/components/SignUp/utils.js b/packages/components-faraday/src/components/SignUp/utils.js
index 3a9fd9988..b7cf7a37f 100644
--- a/packages/components-faraday/src/components/SignUp/utils.js
+++ b/packages/components-faraday/src/components/SignUp/utils.js
@@ -5,7 +5,11 @@ import { loginUser } from 'pubsweet-component-login/actions'
 
 import { handleFormError } from '../utils'
 
-export const parseSignupAuthor = ({ token, confirmPassword, ...values }) => ({
+export const parseSignupAuthor = ({
+  token,
+  confirmNewPassword,
+  ...values
+}) => ({
   ...values,
 })
 
@@ -28,7 +32,10 @@ export const login = (dispatch, values, history) =>
 export const confirmUser = (email, token, history) => (values, dispatch) => {
   const request = { ...values, email, token }
   if (values) {
-    return create('/users/reset-password', omit(request, ['confirmPassword']))
+    return create(
+      '/users/reset-password',
+      omit(request, ['confirmNewPassword']),
+    )
       .then(r => {
         const { username } = r
         const { password } = values
-- 
GitLab