Commit 798d9487 authored by MoSelim's avatar MoSelim
Browse files

linting

parent a2743348
......@@ -15,8 +15,11 @@ const AuthenticatedComponent = ({ children, location }) => (
const url = pathname + search
return <Redirect to={`/login?next=${url}`} />
}
if (location.pathname.includes('/create') && !currentUser.isEmailValidated) {
return <Redirect to={'/dashboard'} />
if (
location.pathname.includes('/create') &&
!currentUser.isEmailValidated
) {
return <Redirect to="/dashboard" />
}
return React.cloneElement(children, { currentUser })
}}
......
......@@ -30,7 +30,10 @@ const LinkArea = styled.p`
const CreateButton = ({ disabled }) => (
<LinkArea>
<LinkAction to={ disabled? "#" : "/create"} style={{cursor: disabled? "not-allowed" : ""}}>
<LinkAction
style={{ cursor: disabled ? 'not-allowed' : '' }}
to={disabled ? '#' : '/create'}
>
<Icon color="currentColor" size={3}>
plus
</Icon>
......@@ -49,7 +52,7 @@ const DashboardBase = BaseComponent => ({
<Page>
<Top>
<H1>{pageTitle}</H1>
<CreateButton disabled={!currentUser.isEmailValidated}/>
<CreateButton disabled={!currentUser.isEmailValidated} />
</Top>
{currentUser.admin && !hideSearchBoxes && <SearchBoxes />}
<BaseComponent currentUser={currentUser} {...props}>
......
......@@ -30,7 +30,7 @@ const PaginationPane = styled.div`
justify-content: flex-end;
`
const EmailValidationArea = styled.div`
const EmailValidationArea = styled.div`
button {
float: right;
margin-top: -48px;
......@@ -49,7 +49,7 @@ class MyManuscripts extends React.Component {
sending: false,
}
}
onPageEntered = p => {
onPageEntered = p => {
this.state.history.push(`/dashboard?completed=true&page=${p}`)
}
resendValidationEmail = () => {
......@@ -59,258 +59,262 @@ class MyManuscripts extends React.Component {
errors,
history,
sending: true,
})
const options = {
mutation: RESEND_VALIDATION_EMAIL,
variables: {
input: {},
},
}
this.props.client
.mutate(options)
.then(response => {
this.setState({ sending: false })
})
.catch(e => {
this.setState({ sending: false })
})
})
const options = {
mutation: RESEND_VALIDATION_EMAIL,
variables: {
input: {},
},
}
this.props.client
.mutate(options)
.then(response => {
this.setState({ sending: false })
})
.catch(e => {
this.setState({ sending: false })
})
}
render() {
const { currentUser, errors, history } = this.state
return (
<Query fetchPolicy="cache-and-network" query={COUNT_MANUSCRIPTS}>
{({ data, loading }) => {
if (loading || !data) {
return (
<Loading>
<LoadingIcon />
</Loading>
return (
<Query fetchPolicy="cache-and-network" query={COUNT_MANUSCRIPTS}>
{({ data, loading }) => {
if (loading || !data) {
return (
<Loading>
<LoadingIcon />
</Loading>
)
}
// get the total number of manuscripts to decide whether the toggles are required
const { countByStatus } = data
const done = states.indexOf('xml-complete')
const totalCount = countByStatus.reduce(
(sum, status) => sum + parseInt(status.count, 10),
0,
)
}
// get the total number of manuscripts to decide whether the toggles are required
const { countByStatus } = data
const done = states.indexOf('xml-complete')
const totalCount = countByStatus.reduce(
(sum, status) => sum + parseInt(status.count, 10),
0,
)
const totalComplete = countByStatus
.filter(s => states.slice(done).includes(s.type))
.reduce((sum, status) => sum + parseInt(status.count, 10), 0)
const togglesRequired = totalCount > pageSize && totalComplete > 0
// determine the query and variables used to get manuscripts
const query = togglesRequired ? MANUSCRIPTS_BY_STATUS : USER_MANUSCRIPTS
const params = new URLSearchParams(history.location.search)
// togglesRequired and on the completed toggle
const completed = params.get('completed')
const totalComplete = countByStatus
.filter(s => states.slice(done).includes(s.type))
.reduce((sum, status) => sum + parseInt(status.count, 10), 0)
const togglesRequired = totalCount > pageSize && totalComplete > 0
// determine the query and variables used to get manuscripts
const query = togglesRequired
? MANUSCRIPTS_BY_STATUS
: USER_MANUSCRIPTS
const params = new URLSearchParams(history.location.search)
// togglesRequired and on the completed toggle
const completed = params.get('completed')
const variables = {}
if (togglesRequired) {
if (completed) {
variables.query = states.slice(done).join(',')
variables.page = params.get('page') ? params.get('page') - 1 : 0
variables.pageSize = pageSize
} else {
variables.query = states.slice(0, done).join(',')
variables.page = -1
const variables = {}
if (togglesRequired) {
if (completed) {
variables.query = states.slice(done).join(',')
variables.page = params.get('page') ? params.get('page') - 1 : 0
variables.pageSize = pageSize
} else {
variables.query = states.slice(0, done).join(',')
variables.page = -1
}
}
}
return (
<Query
fetchPolicy="cache-and-network"
query={query}
variables={variables}
>
{({ data, loading, errors: dErrors }) => {
if (loading) {
return (
<Loading>
<LoadingIcon />
</Loading>
)
}
if (dErrors) {
return dErrors.map(e => (
<Notification type="error">{e.message}</Notification>
))
}
const manuscripts = togglesRequired
? data.findByStatus.manuscripts
: data.manuscripts
const total = togglesRequired
? data.findByStatus.total
: data.manuscripts.length
const toggles = togglesRequired && (
<React.Fragment>
<ToggleBar>
<Link
className={!completed ? 'current' : ''}
to="/dashboard"
>
In process
</Link>
<Link
className={completed ? `current (${total})` : ''}
to="/dashboard?completed=true"
>
Completed
</Link>
</ToggleBar>
<SearchBoxes reviewer />
</React.Fragment>
)
if (completed) {
const currentPage = params.get('page')
? parseInt(params.get('page'), 10)
: 1
return (
<Query
fetchPolicy="cache-and-network"
query={query}
variables={variables}
>
{({ data, loading, errors: dErrors }) => {
if (loading) {
return (
<Loading>
<LoadingIcon />
</Loading>
)
}
if (dErrors) {
return dErrors.map(e => (
<Notification type="error">{e.message}</Notification>
))
}
const manuscripts = togglesRequired
? data.findByStatus.manuscripts
: data.manuscripts
const total = togglesRequired
? data.findByStatus.total
: data.manuscripts.length
const PageNavigation = () => (
<PaginationPane>
<Pagination
currentPage={currentPage}
onPageEntered={onPageEntered}
pageSize={pageSize}
totalSize={total}
/>
</PaginationPane>
)
return (
const toggles = togglesRequired && (
<React.Fragment>
{toggles}
{total && <PageNavigation />}
<DashboardList
currentUser={currentUser}
listData={manuscripts}
/>
{total && <PageNavigation />}
<ToggleBar>
<Link
className={!completed ? 'current' : ''}
to="/dashboard"
>
In process
</Link>
<Link
className={completed ? `current (${total})` : ''}
to="/dashboard?completed=true"
>
Completed
</Link>
</ToggleBar>
<SearchBoxes reviewer />
</React.Fragment>
)
}
const attention = []
const warning = []
const processing = []
const complete = []
const highlight = [
'INITIAL',
'READY',
'submission-error',
'in-review',
'xml-review',
]
manuscripts.forEach(m => {
const reviewer = m.teams.find(t => t.role === 'reviewer')
const submitter = m.teams.find(t => t.role === 'submitter')
if (highlight.includes(m.status)) {
if (
reviewer &&
reviewer.teamMembers[0].user.id === currentUser.id &&
highlight.slice(-2).includes(m.status)
) {
attention.push(m)
if (completed) {
const currentPage = params.get('page')
? parseInt(params.get('page'), 10)
: 1
const PageNavigation = () => (
<PaginationPane>
<Pagination
currentPage={currentPage}
onPageEntered={onPageEntered}
pageSize={pageSize}
totalSize={total}
/>
</PaginationPane>
)
return (
<React.Fragment>
{toggles}
{total && <PageNavigation />}
<DashboardList
currentUser={currentUser}
listData={manuscripts}
/>
{total && <PageNavigation />}
</React.Fragment>
)
}
const attention = []
const warning = []
const processing = []
const complete = []
const highlight = [
'INITIAL',
'READY',
'submission-error',
'in-review',
'xml-review',
]
manuscripts.forEach(m => {
const reviewer = m.teams.find(t => t.role === 'reviewer')
const submitter = m.teams.find(t => t.role === 'submitter')
if (highlight.includes(m.status)) {
if (
reviewer &&
reviewer.teamMembers[0].user.id === currentUser.id &&
highlight.slice(-2).includes(m.status)
) {
attention.push(m)
} else if (
submitter.teamMembers[0].user.id === currentUser.id &&
highlight.slice(0, 3).includes(m.status)
) {
attention.push(m)
} else {
warning.push(m)
}
} else if (
submitter.teamMembers[0].user.id === currentUser.id &&
highlight.slice(0, 3).includes(m.status)
!togglesRequired &&
states.slice(done).includes(m.status)
) {
attention.push(m)
complete.push(m)
} else {
warning.push(m)
processing.push(m)
}
} else if (
!togglesRequired &&
states.slice(done).includes(m.status)
) {
complete.push(m)
} else {
processing.push(m)
}
})
return (
<React.Fragment>
{toggles}
{manuscripts.length === 0 && (
<Notification type="info">
There are currently no manuscripts connected to this
account.
</Notification>
)}
{errors.map(e => (
<Notification
key="message"
type={e.type ? e.type : 'warning'}
>
{e.message}
</Notification>
))}
{!currentUser.isEmailValidated && (
<EmailValidationArea>
})
return (
<React.Fragment>
{toggles}
{manuscripts.length === 0 && (
<Notification type="info">
There are currently no manuscripts connected to this
account.
</Notification>
)}
{errors.map(e => (
<Notification
key="message"
type='warning'
type={e.type ? e.type : 'warning'}
>
Your emall is not validated
{e.message}
</Notification>
<Button primary onClick={this.resendValidationEmail} disabled={this.state.sending}>
Resend validation email
))}
{!currentUser.isEmailValidated && (
<EmailValidationArea>
<Notification key="message" type="warning">
Your emall is not validated
</Notification>
<Button
disabled={this.state.sending}
onClick={this.resendValidationEmail}
primary
>
Resend validation email
</Button>
{(this.state.sending && <Loading>
<LoadingIcon />
</Loading>
)}
</EmailValidationArea>
)}
{attention.length > 0 && (
<React.Fragment>
<H2>Needs my attention ({attention.length})</H2>
<DashboardList
currentUser={currentUser}
listData={attention}
sectionColor="error"
/>
</React.Fragment>
)}
{warning.length > 0 && (
<React.Fragment>
<H2>
Waiting for action by another user ({warning.length})
</H2>
<DashboardList
currentUser={currentUser}
listData={warning}
sectionColor="warning"
/>
</React.Fragment>
)}
{processing.length > 0 && (
<React.Fragment>
<H2>In process at Europe PMC ({processing.length})</H2>
<DashboardList
currentUser={currentUser}
listData={processing}
/>
</React.Fragment>
)}
{complete.length > 0 && (
<React.Fragment>
<H2>Submission complete ({complete.length})</H2>
<DashboardList
listData={complete}
sectionRole="submitter"
/>
</React.Fragment>
)}
</React.Fragment>
)
}}
</Query>
)
}}
</Query>
)
}
{this.state.sending && (
<Loading>
<LoadingIcon />
</Loading>
)}
</EmailValidationArea>
)}
{attention.length > 0 && (
<React.Fragment>
<H2>Needs my attention ({attention.length})</H2>
<DashboardList
currentUser={currentUser}
listData={attention}
sectionColor="error"
/>
</React.Fragment>
)}
{warning.length > 0 && (
<React.Fragment>
<H2>
Waiting for action by another user ({warning.length})
</H2>
<DashboardList
currentUser={currentUser}
listData={warning}
sectionColor="warning"
/>
</React.Fragment>
)}
{processing.length > 0 && (
<React.Fragment>
<H2>In process at Europe PMC ({processing.length})</H2>
<DashboardList
currentUser={currentUser}
listData={processing}
/>
</React.Fragment>
)}
{complete.length > 0 && (
<React.Fragment>
<H2>Submission complete ({complete.length})</H2>
<DashboardList
listData={complete}
sectionRole="submitter"
/>
</React.Fragment>
)}
</React.Fragment>
)
}}
</Query>
)
}}
</Query>
)
}
}
export default withApollo(MyManuscripts)
......@@ -5,7 +5,6 @@ import { H1, Link, Button } from '@pubsweet/ui'
import { Page, Loading, LoadingIcon, Notification } from '../ui'
import { VALIDATE_EMAIL } from './mutations'
class EmailValidation extends React.Component {
constructor(props) {
super(props)
......@@ -19,26 +18,26 @@ class EmailValidation extends React.Component {
}
componentWillMount = () => {
const { currentUser, history, token } = this.state
console.log(token);
console.log(token)
this.setState({
currentUser,
history,
sending: true,
})
const options = {
mutation: VALIDATE_EMAIL,
variables: {
token: token,
},
}
this.props.client
.mutate(options)
.then(response => {
this.setState({ sending: false, result: 'success' })
})
.catch(e => {
this.setState({ sending: false, result: 'failure' })
})
})
const options = {
mutation: VALIDATE_EMAIL,
variables: {
token,
},
}
this.props.client
.mutate(options)
.then(response => {
this.setState({ sending: false, result: 'success' })
})
.catch(e => {