Skip to content
Snippets Groups Projects
Commit 3b52da0e authored by Sebastian's avatar Sebastian
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into develop

parents 35830158 261390e0
No related branches found
No related tags found
1 merge request!6Agree/Decline to work on a manuscript
......@@ -5,6 +5,7 @@ import { compose, lifecycle } from 'recompose'
import { selectCurrentUser } from 'xpub-selectors'
import { parseSearchParams } from './utils'
import { reviewerDecision } from '../../../components-faraday/src/redux/reviewers'
const Details = () => <div>eu sunt manuscript details</div>
......@@ -13,13 +14,15 @@ export default compose(
state => ({
currentUser: selectCurrentUser(state),
}),
{ replace },
{ reviewerDecision, replace },
),
lifecycle({
componentDidMount() {
const { location, replace } = this.props
const { accept } = parseSearchParams(location.search)
if (accept === 'true') {
const { reviewerDecision, location, match, replace } = this.props
const collectionId = match.params.project
const { agree, invitationId } = parseSearchParams(location.search)
if (agree === 'true') {
reviewerDecision(invitationId, collectionId, true)
replace(location.pathname)
}
},
......
import React from 'react'
import { connect } from 'react-redux'
import { reduxForm } from 'redux-form'
import { push } from 'react-router-redux'
import { required, minChars } from 'xpub-validators'
import { Button, ValidatedField, TextField } from '@pubsweet/ui'
import { compose, withState, lifecycle } from 'recompose'
import { loginUser } from 'pubsweet-component-login/actions'
import { Button, ValidatedField, TextField } from '@pubsweet/ui'
import {
Row,
......@@ -17,14 +19,15 @@ import {
FormContainer,
} from './FormItems'
import { parseSearchParams } from './utils'
import {
setReviewerPassword,
reviewerAccept,
reviewerDecline,
} from '../../redux/reviewers'
import { reviewerDecision, setReviewerPassword } from '../../redux/reviewers'
const min8Chars = minChars(8)
const ReviewerSignUp = ({ handleSubmit, error, reviewer }) => (
const ReviewerSignUp = ({
searchParams: { agree },
handleSubmit,
error,
reviewer,
}) => (
<RootContainer>
<Title>Hindawi Invitation</Title>
<Subtitle>
......@@ -32,47 +35,62 @@ const ReviewerSignUp = ({ handleSubmit, error, reviewer }) => (
Please set a password and proceed to the manuscript.
</Subtitle>
<Email>{reviewer.email}</Email>
<FormContainer onSubmit={handleSubmit}>
<Row>
<RowItem>
<Label> Password </Label>
<ValidatedField
component={input => <TextField {...input} type="password" />}
name="password"
validate={[required, min8Chars]}
/>
</RowItem>
</Row>
{error && (
{agree ? (
<FormContainer onSubmit={handleSubmit}>
<Row>
<RowItem>
<Err>{error}</Err>
<Label> Password </Label>
<ValidatedField
component={input => <TextField {...input} type="password" />}
name="password"
validate={[required, min8Chars]}
/>
</RowItem>
</Row>
)}
<Row>
<Button primary type="submit">
CONFIRM
</Button>
</Row>
</FormContainer>
{error && (
<Row>
<RowItem>
<Err>{error}</Err>
</RowItem>
</Row>
)}
<Row>
<Button primary type="submit">
CONFIRM
</Button>
</Row>
</FormContainer>
) : (
<span>sorry</span>
)}
</RootContainer>
)
export default compose(
withState('searchParams', 'setParams', { agree: true }),
withState('reviewer', 'setReviewer', {}),
connect(null, { setReviewerPassword, reviewerAccept, reviewerDecline }),
connect(null, { push, loginUser, setReviewerPassword, reviewerDecision }),
lifecycle({
componentDidMount() {
const { location, setReviewer, reviewerDecline } = this.props
const { decision = true, ...reviewerBody } = parseSearchParams(
location.search,
)
const { setParams, location, setReviewer, reviewerDecision } = this.props
const {
agree,
collectionId,
invitationId,
fragmentId,
...reviewerBody
} = parseSearchParams(location.search)
setParams(v => ({
agree: agree === 'true',
collectionId,
invitationId,
fragmentId,
}))
if (decision) {
if (agree === 'true') {
setReviewer(reviewerBody)
} else {
reviewerDecline()
reviewerDecision(invitationId, collectionId, false)
}
},
}),
......@@ -81,11 +99,24 @@ export default compose(
onSubmit: (
{ password },
dispatch,
{ reviewer, location, setReviewerPassword },
{
push,
loginUser,
searchParams,
reviewer,
location,
setReviewerPassword,
},
) => {
const { collectionId, fragmentId, agree, invitationId } = searchParams
setReviewerPassword({
...reviewer,
password,
}).then(() => {
loginUser(
{ username: reviewer.email, password },
`/projects/${collectionId}/versions/${fragmentId}/details?agree=${agree}&invitationId=${invitationId}`,
)
})
},
}),
......
import { get } from 'lodash'
import { get as apiGet, create, remove } from 'pubsweet-client/src/helpers/api'
import {
get as apiGet,
create,
remove,
update,
} from 'pubsweet-client/src/helpers/api'
const GET_REVIEWERS_REQUEST = 'GET_REVIEWERS_REQUEST'
const GET_REVIEWERS_ERROR = 'GET_REVIEWERS_ERROR'
......@@ -43,10 +48,10 @@ const REVIEWER_DECISION_ERROR = 'REVIEWER_DECISION_ERROR'
const REVIEWER_DECISION_SUCCESS = 'REVIEWER_DECISION_SUCCESS'
const reviewerDecisionRequest = () => ({ type: REVIEWER_DECISION_REQUEST })
// const reviewerDecisionError = error => ({
// type: REVIEWER_DECISION_ERROR,
// error,
// })
const reviewerDecisionError = error => ({
type: REVIEWER_DECISION_ERROR,
error,
})
const reviewerDecisionSuccess = () => ({ type: REVIEWER_DECISION_SUCCESS })
const initialState = {
......@@ -101,26 +106,25 @@ export const revokeReviewer = (invitationId, collectionId) => dispatch => {
}
// reviewer decision actions
export const reviewerAccept = () => dispatch => {
export const reviewerDecision = (
invitationId,
collectionId,
agree = true,
) => dispatch => {
dispatch(reviewerDecisionRequest())
// 'accept api call'
return new Promise(resolve => {
setTimeout(() => {
return update(`/collections/${collectionId}/invitations/${invitationId}`, {
isAccepted: agree,
}).then(
res => {
dispatch(reviewerDecisionSuccess())
resolve({ name: 'coco' })
}, 1500)
})
}
export const reviewerDecline = () => dispatch => {
dispatch(reviewerDecisionRequest())
// 'decline api call'
return new Promise(resolve => {
setTimeout(() => {
dispatch(reviewerDecisionSuccess())
resolve({ name: 'coco' })
}, 1500)
})
return res
},
err => {
dispatch(reviewerDecisionError(err.message))
return err
},
)
}
export default (state = initialState, action = {}) => {
......
......@@ -62,7 +62,11 @@ const Routes = () => (
/>
<Route component={SignUpInvitationPage} exact path="/invite" />
<Route component={ReviewerSignUp} exact path="/invite-reviewer" />
<PrivateRoute component={ManuscriptDetails} exact path="/manu-details" />
<PrivateRoute
component={ManuscriptDetails}
exact
path="/projects/:project/versions/:version/details"
/>
<Route component={NotFound} />
</Switch>
</FaradayApp>
......
const omit = require('lodash/omit')
const config = require('config')
const statuses = config.get('statuses')
const publicStatusesPermissions = ['author', 'reviewer']
module.exports = {
parseReviewerAuthors: (coll, matchingCollPerm) => {
if (['reviewer'].includes(matchingCollPerm.permission)) {
coll.authors = coll.authors.map(a => omit(a, ['email']))
}
},
setPublicStatuses: (coll, matchingCollPerm) => {
coll.visibleStatus = statuses[coll.status].public
if (!publicStatusesPermissions.includes(matchingCollPerm.permission)) {
coll.visibleStatus = statuses[coll.status].private
}
},
}
const get = require('lodash/get')
const pickBy = require('lodash/pickBy')
const omit = require('lodash/omit')
const config = require('config')
const helpers = require('./authsome-helpers')
const statuses = config.get('statuses')
async function teamPermissions(user, operation, object, context) {
const permissions = ['handlingEditor', 'author', 'reviewer']
const teams = await Promise.all(
......@@ -20,7 +19,6 @@ async function teamPermissions(user, operation, object, context) {
id: team.object.id,
permission: team.teamType.permissions,
}))
const publicPermissions = ['author', 'reviewer']
if (collectionsPermissions.length > 0) {
return {
......@@ -35,10 +33,8 @@ async function teamPermissions(user, operation, object, context) {
if (matchingCollPerm === undefined) {
return null
}
coll.visibleStatus = statuses[coll.status].public
if (!publicPermissions.includes(matchingCollPerm.permission)) {
coll.visibleStatus = statuses[coll.status].private
}
helpers.setPublicStatuses(coll, matchingCollPerm)
helpers.parseReviewerAuthors(coll, matchingCollPerm)
return coll
})
.filter(Boolean)
......
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