import React, { Component } from 'react'
import {graphql, compose} from 'react-apollo'
import {getUsersBySearchFields} from '../queries/queries'
// Materia UI
import { withStyles } from '@material-ui/core/styles'
import Card from '@material-ui/core/Card'
import CardActionArea from '@material-ui/core/CardActionArea'
import CardActions from '@material-ui/core/CardActions'
import CardContent from '@material-ui/core/CardContent'
import CardMedia from '@material-ui/core/CardMedia'
import Button from '@material-ui/core/Button'
import Typography from '@material-ui/core/Typography'
import Grid from '@material-ui/core/Grid'
import TextField from '@material-ui/core/TextField'
// Images
import PortraitImage from '../img/portrait.jpg'
const styles = theme => ({
card: {
maxWidth: 150,
minWidth: 150,
paddingTop: '30',
marginBottom: 40
},
media: {
height: 0,
paddingTop: '56.25%', // 16:9,
marginTop: '30',
minWidth: 300
},
typography: {
maxWidth: 345,
minWidth: 300,
paddingTop: '30'
},
appBar: {
position: 'relative'
},
flex: {
flex: 1
},
grid: {
paddingTop: '30',
marginTop: 30
},
inputField: {
width: '80%',
marginLeft: '10%',
marginTop: 25
},
formTypography: {
width: '80%',
marginLeft: '10%',
marginTop: 40
},
button: {
margin: theme.spacing.unit,
marginTop: theme.spacing.unit * 3
}
})
class UserSearch extends Component {
constructor (props) {
super(props)
this.state = {
alias: '',
firstName: '',
middleName: '',
lastName: ''
}
}
submitForm (e) {
e.preventDefault()
this.props.getUsersBySearchFields.variables.alias = this.state.alias
this.props.getUsersBySearchFields.variables.firstName = this.state.firstName
this.props.getUsersBySearchFields.variables.middleName = this.state.middleName
this.props.getUsersBySearchFields.variables.lastName = this.state.lastName
this.props.getUsersBySearchFields.refetch({})
}
handleTextField (e) {
/*
We will do some basic input validations here. If something is wrong we will turn on the error sign on the textfield.
*/
let value = e.target.value
switch (e.target.id) {
case 'alias':
if (value.length > 30) {
this.setState({aliasError: true})
} else {
this.setState({aliasError: false, alias: value})
}
break
case 'firstName':
if (value.length > 30) {
this.setState({firstNameError: true})
} else {
this.setState({firstNameError: false, firstName: value})
}
break
case 'middleName':
if (value.length > 30) {
this.setState({middleNameError: true})
} else {
this.setState({middleNameError: false, middleName: value})
}
break
case 'lastName':
if (value.length > 50) {
this.setState({lastNameError: true})
} else {
this.setState({lastNameError: false, lastName: value})
}
break
default:
}
}
selectText () {
if (this.props.selectButton === true) {
return (