Commit b9154f92 authored by Audrey Hamelers's avatar Audrey Hamelers

#476 admin select reviewer by ID

parent c151a90e
Pipeline #12969 passed with stages
in 3 minutes and 17 seconds
......@@ -2,9 +2,10 @@ import React from 'react'
import { ApolloConsumer } from 'react-apollo'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { TextField, RadioGroup, ErrorText, H2, H3 } from '@pubsweet/ui'
import { LoadingIcon, Notification } from '../ui'
import { Action, TextField, RadioGroup, ErrorText, H2, H3 } from '@pubsweet/ui'
import { LoadingIcon, Notification, Toggle } from './ui'
import { GET_USER } from './operations'
import UserIdSearch from './UserIdSearch'
const Joi = require('joi')
......@@ -23,13 +24,21 @@ const NewReviewerForm = styled.div`
display: flex;
align-items: flex-start;
flex-wrap: wrap;
margin-bottom: calc(${th('gridUnit')} * 2);
& > * {
padding: 0 calc(${th('gridUnit')} * 2);
width: calc(${th('gridUnit')} * 42);
}
button {
font-size: ${th('fontSizeBaseSmall')};
}
`
const SearchArea = styled.div`
padding: 0 calc(${th('gridUnit')} * 2);
`
class SelectReviewer extends React.Component {
state = {
showToggle: false,
newFormDisabled: true,
loading: true,
options: [],
......@@ -121,6 +130,7 @@ class SelectReviewer extends React.Component {
surname: selectedReviewer.name.surname,
email: selectedReviewer.email,
newFormDisabled: false,
showToggle: true,
}
}
}
......@@ -143,10 +153,17 @@ class SelectReviewer extends React.Component {
surname,
email,
newFormDisabled,
showToggle,
options,
loading,
} = this.state
const { funding, reviewer, reviewerNote, submitter } = this.props
const {
currentUser,
funding,
reviewer,
reviewerNote,
submitter,
} = this.props
return (
<ApolloConsumer>
{client => {
......@@ -196,12 +213,15 @@ class SelectReviewer extends React.Component {
}
const setReviewer = async value => {
if (value === 'new') {
this.setState({ newFormDisabled: false }, () => {
this.nameInput.querySelector('input').focus()
})
this.setState(
{ showToggle: true, newFormDisabled: false },
() => {
this.nameInput.querySelector('input').focus()
},
)
} else {
const newReviewer = {}
this.setState({ newFormDisabled: true })
this.setState({ showToggle: false, newFormDisabled: true })
if (value === 'reviewer') {
if (reviewerNote) {
this.props.setReviewerNote('delete')
......@@ -231,6 +251,21 @@ class SelectReviewer extends React.Component {
}
}
}
const setReviewerWithId = user => {
const { name, email } = user.identities[0]
const newReviewer = {
id: user.id,
name,
email,
}
this.props.setReviewerNote(newReviewer)
this.setState({
name: name.givenNames,
surname: name.surname,
email,
newFormDisabled: false,
})
}
return (
<div>
<H2>Reviewer</H2>
......@@ -257,6 +292,36 @@ class SelectReviewer extends React.Component {
options={options}
value={selected}
/>
{currentUser.admin && showToggle && (
<NewReviewerForm>
<Toggle>
<Action
className={!newFormDisabled && 'current'}
onClick={() =>
this.setState({ newFormDisabled: false })
}
>
Enter new
</Action>
<Action
className={newFormDisabled && 'current'}
onClick={() =>
this.setState({ newFormDisabled: true })
}
>
Enter ID
</Action>
</Toggle>
</NewReviewerForm>
)}
{showToggle && newFormDisabled && (
<SearchArea>
<UserIdSearch
success={user => setReviewerWithId(user)}
successLabel="Select"
/>
</SearchArea>
)}
{!newFormDisabled && (
<NewReviewerForm>
<div ref={this.setNameRef}>
......
import gql from 'graphql-tag'
export const GET_USER = gql`
query($email: String!) {
userByEmail(email: $email) {
id
}
}
`
export const GET_USER_ID = gql`
query($id: ID!) {
epmc_user(id: $id) {
......
......@@ -23,10 +23,10 @@ import { NoteMutations, ManuscriptMutations } from '../SubmissionMutations'
import SubmissionCancel from '../SubmissionCancel'
import { GET_MANUSCRIPT } from '../operations'
import GrantSearch from '../GrantSearch'
import SelectReviewer from '../SelectReviewer'
import CreatePageHeader from './CreateHeader'
import CreateInfo from './CreateInfo'
import Citation from './Citation'
import SelectReviewer from './SelectReviewer'
const FadeIn = createGlobalStyle`
@keyframes fadeIn {
......
......@@ -4,8 +4,8 @@ import { th } from '@pubsweet/ui-toolkit'
import { Button, H2, Icon } from '@pubsweet/ui'
import { SplitPage, StepPanel, InfoPanel, Buttons, CloseModal } from '../ui'
import UploadFiles, { SubmissionTypes } from '../upload-files'
import SelectReviewer from '../SelectReviewer'
import CreateInfo from './CreateInfo'
import SelectReviewer from './SelectReviewer'
const CloseEdit = styled(CloseModal)`
margin: calc(${th('gridUnit')} * 6) auto calc(${th('gridUnit')} * 2);
......
......@@ -9,14 +9,6 @@ export const CURRENT_USER = gql`
}
`
export const GET_USER = gql`
query($email: String!) {
userByEmail(email: $email) {
id
}
}
`
export const CREATE_MANUSCRIPT = gql`
mutation CreateManuscript($data: CreateManuscriptInput!) {
createManuscript(data: $data) {
......
Markdown is supported
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