Skip to content
Snippets Groups Projects
Commit 06b5d29b authored by MoSelim's avatar MoSelim
Browse files

#450

parent 60e4d296
No related branches found
No related tags found
2 merge requests!101Shared data model,!102Shared data model
...@@ -3,7 +3,14 @@ import styled from 'styled-components' ...@@ -3,7 +3,14 @@ import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit' import { th } from '@pubsweet/ui-toolkit'
import { H1, Link } from '@pubsweet/ui' import { H1, Link } from '@pubsweet/ui'
import { withApollo } from 'react-apollo' import { withApollo } from 'react-apollo'
import { Page, SearchForm, ZebraList, ZebraListItem } from '../ui/' import {
Page,
SearchForm,
ZebraList,
ZebraListItem,
Loading,
LoadingIcon,
} from '../ui/'
import { USERS_BY_NAME, USERS_BY_EMAIL } from './queries' import { USERS_BY_NAME, USERS_BY_EMAIL } from './queries'
const SearchArea = styled.div` const SearchArea = styled.div`
...@@ -45,6 +52,7 @@ class UserSearch extends React.Component { ...@@ -45,6 +52,7 @@ class UserSearch extends React.Component {
searchByName: props.searchByName ? props.searchByName : '', searchByName: props.searchByName ? props.searchByName : '',
searchByEmail: props.searchByEmail ? props.searchByEmail : '', searchByEmail: props.searchByEmail ? props.searchByEmail : '',
results: [], results: [],
emptyResults: false,
} }
this.onSearchValChanged = this.onSearchValChanged.bind(this) this.onSearchValChanged = this.onSearchValChanged.bind(this)
this.onSearchValSubmitted = this.onSearchValSubmitted.bind(this) this.onSearchValSubmitted = this.onSearchValSubmitted.bind(this)
...@@ -61,21 +69,31 @@ class UserSearch extends React.Component { ...@@ -61,21 +69,31 @@ class UserSearch extends React.Component {
variables: { name: this.state.searchByName }, variables: { name: this.state.searchByName },
fetchPolicy: 'network-only', fetchPolicy: 'network-only',
} }
this.setState({ searchByEmail: '' }) this.setState({ searchByEmail: '', loading: true })
} else { } else {
options = { options = {
query: USERS_BY_EMAIL, query: USERS_BY_EMAIL,
variables: { email: this.state.searchByEmail }, variables: { email: this.state.searchByEmail },
fetchPolicy: 'network-only', fetchPolicy: 'network-only',
} }
this.setState({ searchByName: '' }) this.setState({ searchByName: '', loading: true })
} }
this.props.client this.props.client.query(options).then(response =>
.query(options) this.setState({
.then(response => this.setState({ results: response.data[searchForm] })) results: response.data[searchForm],
loading: false,
emptyResults: response.data[searchForm].length === 0,
}),
)
} }
render() { render() {
const { searchByName, searchByEmail, results } = this.state const {
searchByName,
searchByEmail,
results,
loading,
emptyResults,
} = this.state
return ( return (
<Page> <Page>
<H1>Manage Users</H1> <H1>Manage Users</H1>
...@@ -128,6 +146,12 @@ class UserSearch extends React.Component { ...@@ -128,6 +146,12 @@ class UserSearch extends React.Component {
) )
})} })}
</ZebraList> </ZebraList>
{loading && (
<Loading>
<LoadingIcon />
</Loading>
)}
{emptyResults && <div> No results found for this search.</div>}
</div> </div>
</Page> </Page>
) )
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment