diff --git a/packages/component-manuscript/src/components/Details.js b/packages/component-manuscript/src/components/Details.js index 2249fc2a1382e791a0f37f528b424b0621d5b77e..1445da287ee2c392472c5a823cb2cf6bccaee221 100644 --- a/packages/component-manuscript/src/components/Details.js +++ b/packages/component-manuscript/src/components/Details.js @@ -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) } }, diff --git a/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js b/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js index 3598fe6b145ed47d5a63351fe521d1e261d516c2..0e6ec99383791e74a04ef47934c1688cc7d4ca34 100644 --- a/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js +++ b/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js @@ -1,9 +1,11 @@ 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}`, + ) }) }, }), diff --git a/packages/components-faraday/src/redux/reviewers.js b/packages/components-faraday/src/redux/reviewers.js index d8e5fbc0dc38fc5fc9157ddb12a06123931e3b08..a54bd5ab18ae06377728cabdf856fa78588b37a0 100644 --- a/packages/components-faraday/src/redux/reviewers.js +++ b/packages/components-faraday/src/redux/reviewers.js @@ -1,5 +1,10 @@ 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 = {}) => { diff --git a/packages/xpub-faraday/app/routes.js b/packages/xpub-faraday/app/routes.js index c65e01a8ebbca217f5f75c59d8dbb15228b4d8dd..4eca5f8fc8556beca13751bca253bd7b6e50e648 100644 --- a/packages/xpub-faraday/app/routes.js +++ b/packages/xpub-faraday/app/routes.js @@ -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> diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js new file mode 100644 index 0000000000000000000000000000000000000000..fb41c77335450135b350cd8c3580e23750cf8722 --- /dev/null +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -0,0 +1,20 @@ +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 + } + }, +} diff --git a/packages/xpub-faraday/config/authsome.js b/packages/xpub-faraday/config/authsome.js index 5a31c01fa64572459d0e01c36b7f76cb5c318ac7..9418e830bf2700f23aaccbce52939cb816f23936 100644 --- a/packages/xpub-faraday/config/authsome.js +++ b/packages/xpub-faraday/config/authsome.js @@ -1,9 +1,8 @@ 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)