diff --git a/client/src/components/UserReferrals.js b/client/src/components/UserReferrals.js
index 28c83a2e7..6e6fb8a1a 100644
--- a/client/src/components/UserReferrals.js
+++ b/client/src/components/UserReferrals.js
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import {graphql, compose} from 'react-apollo'
-import {getRolesQuery, updateUserMutation, getUsersQuery} from '../queries/queries'
+import {getRolesQuery, updateReferrerMutation, getUsersQuery} from '../queries/queries'
// components
@@ -44,6 +44,8 @@ class UserReferrals extends Component {
this.defaultValuesSet = false
this.state = {
+ id: '',
+ referrerId: '',
firstNameError: false,
middleNameError: false,
lastNameError: false,
@@ -51,41 +53,23 @@ class UserReferrals extends Component {
}
}
- userSelected (user) {
+ userSelected (referrerUser) {
console.log(user)
- this.setState({referrer: user.id})
- }
+ this.setState({referrer: referrerUser.id})
- submitForm (e) {
- e.preventDefault()
- this.props.updateUserMutation({
+ this.props.updateReferrerMutation({
variables: {
id: this.state.id,
- firstName: this.state.firstName,
- middleName: this.state.middleName,
- lastName: this.state.lastName,
- bio: this.state.bio,
- isDeveloper: this.state.isDeveloper,
- isTrader: this.state.isTrader,
- isDataAnalyst: this.state.isDataAnalyst,
- roleId: this.state.roleId
- },
- refetchQueries: [{ query: getUsersQuery}] // This allow us to re run whatever queries are necesary after the mutation.
+ referrerId: referrerUser.id
+ }
})
/* Before we are done, we need to update the state of the local storage. */
let user = JSON.parse(localStorage.getItem('loggedInUser'))
- user.firstName = this.state.firstName
- user.middleName = this.state.middleName
- user.lastName = this.state.lastName
- user.bio = this.state.bio
- user.isDeveloper = this.state.isDeveloper
- user.isTrader = this.state.isTrader
- user.isDataAnalyst = this.state.isDataAnalyst
- user.role.id = this.state.roleId
+ user.referrerId = referrerUser.id
localStorage.setItem('loggedInUser', JSON.stringify(user))
}
@@ -99,28 +83,11 @@ class UserReferrals extends Component {
let user = JSON.parse(userData)
this.defaultValuesSet = true
- /* To avoid console warning, we need to take care of the fields that are null. */
-
- if (user.firstName === null) { user.firstName = '' }
- if (user.middleName === null) { user.middleName = '' }
- if (user.lastName === null) { user.lastName = '' }
- if (user.bio === null) { user.bio = '' }
-
/* Now we are ready to set the initial state. */
this.setState({
id: user.id,
- alias: user.alias,
- email: user.email,
- emailVerified: user.emailVerified,
- firstName: user.firstName,
- middleName: user.middleName,
- lastName: user.lastName,
- bio: user.bio,
- isDeveloper: user.isDeveloper,
- isTrader: user.isTrader,
- isDataAnalyst: user.isDataAnalyst,
- roleId: user.role.id
+ referrerId: user.referrerId
})
}
}
@@ -132,9 +99,8 @@ class UserReferrals extends Component {