From df4c76e6b294d87944afec362607722db9edb67e Mon Sep 17 00:00:00 2001
From: Alexandru Munteanu <alexandru.munt@gmail.com>
Date: Fri, 13 Apr 2018 14:01:13 +0300
Subject: [PATCH] fix(signup-invitation): remove get request

---
 .../components/SignUp/SignUpInvitationForm.js |  2 +-
 .../components/SignUp/SignUpInvitationPage.js | 47 +++++++++----------
 2 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js b/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js
index 6337b777a..1e1b35f9f 100644
--- a/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js
+++ b/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js
@@ -20,7 +20,7 @@ const SignUpInvitation = ({
       Your details have been pre-filled, please review and confirm before set
       your password.
     </Subtitle>
-    <Email>{email}</Email>
+    <Email>{initialValues.email}</Email>
     {error && <Err>Token expired or Something went wrong.</Err>}
     {step === 0 && (
       <Step0
diff --git a/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js b/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js
index c78509321..c6c01d53d 100644
--- a/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js
+++ b/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js
@@ -1,15 +1,9 @@
 import { get } from 'lodash'
-import request, { create } from 'pubsweet-client/src/helpers/api'
+import { create } from 'pubsweet-client/src/helpers/api'
 import { withJournal } from 'xpub-journal'
 import { loginUser } from 'pubsweet-component-login/actions'
 import { SubmissionError } from 'redux-form'
-import {
-  compose,
-  withState,
-  withProps,
-  withHandlers,
-  lifecycle,
-} from 'recompose'
+import { compose, withState, withProps, withHandlers } from 'recompose'
 
 import SignUpInvitation from './SignUpInvitationForm'
 
@@ -52,30 +46,33 @@ const confirmUser = (email, token, history) => (values, dispatch) => {
 export default compose(
   withJournal,
   withState('step', 'changeStep', 0),
-  withState('initialValues', 'setInitialValues', {}),
   withProps(({ location }) => {
     const params = new URLSearchParams(location.search)
     const email = params.get('email')
     const token = params.get('token')
-    return { email, token }
+    const firstName = params.get('firstName')
+    const lastName = params.get('lastName')
+    const affiliation = params.get('affiliation')
+    const title = params.get('title')
+
+    return {
+      initialValues: {
+        email,
+        firstName,
+        lastName,
+        affiliation,
+        title,
+        token,
+      },
+    }
   }),
   withHandlers({
     nextStep: ({ changeStep }) => () => changeStep(step => step + 1),
     prevStep: ({ changeStep }) => () => changeStep(step => step - 1),
-    submitConfirmation: ({ email, token, history }) =>
-      confirmUser(email, token, history),
-  }),
-  lifecycle({
-    componentDidMount() {
-      const { setInitialValues, token } = this.props
-      const encodedUri = `?passwordResetToken=${token}`
-      request(`/users/${encodedUri}`)
-        .then(res => {
-          setInitialValues(v => res.users[0])
-        })
-        .catch(err => {
-          this.setState({ error: err.response })
-        })
-    },
+    submitConfirmation: ({
+      initialValues: { email, token },
+      history,
+      ...rest
+    }) => confirmUser(email, token, history),
   }),
 )(SignUpInvitation)
-- 
GitLab