diff --git a/client/src/components/DescendentsTree.js b/client/src/components/DescendentsTree.js index 3a8ebf1c4..74e72fd36 100644 --- a/client/src/components/DescendentsTree.js +++ b/client/src/components/DescendentsTree.js @@ -66,7 +66,7 @@ const styles = theme => ({ } }) -class YourDescendents extends Component { +class DescendentsTree extends Component { constructor (props) { super(props) @@ -79,22 +79,22 @@ class YourDescendents extends Component { } } - displayUsers () { - let data = this.props.getUsersBySearchFields + displayDescendents () { + let data = this.props.data const { classes } = this.props if (data.loading) { - return (
Loading Users...
) + return (
Loading Descendents...
) } else { - if (data.usersSearch === undefined) { - return (
No Users to Display
) + if (data.descendents === undefined) { + return (
No Descendents to Display
) } else { - return data.usersSearch.map(user => { + return data.descendents.map(descendent => { return ( - + { - this.setState({ selected: user.id}) + this.setState({ selected: descendent.id}) } }> @@ -106,15 +106,13 @@ class YourDescendents extends Component { /> - {user.alias} + {descendent.alias} - - {this.selectButton(user)} - + @@ -130,14 +128,8 @@ class YourDescendents extends Component { const { classes } = this.props return (
- - - These are your decendents within the project. Your children referred you as the one who brought them to the project, while - your grandchildren referred your children and so on. - - - {this.displayUsers()} + {this.displayDescendents()}
) @@ -145,6 +137,14 @@ class YourDescendents extends Component { } export default compose( - graphql(getUsersBySearchFields, {name: 'getUsersBySearchFields'}), + graphql(getDescendentsQuery, { // What follows is the way to pass a parameter to a query. + options: (props) => { + return { + variables: { + name: 'getDescendentsQuery', + id: props.userId + } + } + }}), withStyles(styles) -)(YourDescendents) // This technique binds more than one query to a single component. +)(DescendentsTree) // This technique binds more than one query to a single component. diff --git a/client/src/components/YourDescendents.js b/client/src/components/YourDescendents.js index db59b2870..550f1c846 100644 --- a/client/src/components/YourDescendents.js +++ b/client/src/components/YourDescendents.js @@ -9,7 +9,7 @@ import Grid from '@material-ui/core/Grid' import Paper from '@material-ui/core/Paper' // components -import UserProfile from './UserProfile' +import DescendentsTree from './DescendentsTree' const styles = theme => ({ root: { @@ -36,13 +36,32 @@ class YourDescendents extends Component { constructor (props) { super(props) + this.defaultValuesSet = false + this.state = { id: '' } } + componentWillMount () { + if (this.defaultValuesSet === false) { + let userData = localStorage.getItem('loggedInUser') + + if (userData === 'undefined') { return } + + let user = JSON.parse(userData) + this.defaultValuesSet = true + + /* Now we are ready to set the initial state. */ + this.setState({ + id: user.id + }) + } + } + render () { const { classes } = this.props + return ( @@ -54,6 +73,7 @@ class YourDescendents extends Component { your grandchildren referred your children and so on. + ) diff --git a/client/src/queries/queries.js b/client/src/queries/queries.js index a9015b5db..2071246a1 100644 --- a/client/src/queries/queries.js +++ b/client/src/queries/queries.js @@ -180,6 +180,7 @@ export { getRolesQuery, getUserProfileQuery, getUsersBySearchFields, + getDescendentsQuery, updateUserMutation, updateReferrerMutation, updateUserImagesMutation