diff --git a/packages/components-faraday/src/components/SignUp/ReviewerDecline.js b/packages/components-faraday/src/components/SignUp/ReviewerDecline.js index bf49edaf31d6cbb31e5f748219b8fd8911acc46d..12b6a96b3b6fcf0ed6e94cbcb8cbdb69f5265292 100644 --- a/packages/components-faraday/src/components/SignUp/ReviewerDecline.js +++ b/packages/components-faraday/src/components/SignUp/ReviewerDecline.js @@ -1,5 +1,22 @@ import React from 'react' +import { connect } from 'react-redux' +import { compose, lifecycle } from 'recompose' -const ReviewerDecline = props => <div>I decline</div> +import { reviewerDecline } from '../../redux/reviewers' -export default ReviewerDecline +const ReviewerDecline = props => <div>I decline textul de la Matt</div> + +export default compose( + connect(null, { reviewerDecline }), + lifecycle({ + componentDidMount() { + const { + collectionId, + invitationId, + invitationToken, + reviewerDecline, + } = this.props + reviewerDecline(invitationId, collectionId, invitationToken) + }, + }), +)(ReviewerDecline) diff --git a/packages/components-faraday/src/components/SignUp/ReviewerAgree.js b/packages/components-faraday/src/components/SignUp/ReviewerInviteDecision.js similarity index 65% rename from packages/components-faraday/src/components/SignUp/ReviewerAgree.js rename to packages/components-faraday/src/components/SignUp/ReviewerInviteDecision.js index 4e35309c5b862028c3818e41949f0c3d460255a3..c6db91452b20104118524357941cdaaf968326f9 100644 --- a/packages/components-faraday/src/components/SignUp/ReviewerAgree.js +++ b/packages/components-faraday/src/components/SignUp/ReviewerInviteDecision.js @@ -25,17 +25,17 @@ const agreeText = `You have been invited to review a manuscript on the Hindawi p const declineText = `You have decline to work on a manuscript.` const min8Chars = minChars(8) -const ReviewerSignUp = ({ - searchParams: { agree }, +const ReviewerInviteDecision = ({ handleSubmit, error, - reviewer, + reviewerEmail, + agree, }) => ( <RootContainer> <Title>Hindawi Invitation</Title> - <Subtitle>{agree ? agreeText : declineText}</Subtitle> - <Email>{reviewer.email}</Email> - {agree && ( + <Subtitle>{agree === 'true' ? agreeText : declineText}</Subtitle> + <Email>{reviewerEmail}</Email> + {agree === 'true' && ( <FormContainer onSubmit={handleSubmit}> <Row> <RowItem> @@ -61,35 +61,28 @@ const ReviewerSignUp = ({ </Row> </FormContainer> )} + {agree === 'false' && <div>nu i-a placut</div>} </RootContainer> ) export default compose( - withState('searchParams', 'setParams', { agree: true }), - withState('reviewer', 'setReviewer', {}), + withState('reviewerEmail', 'setEmail', ''), connect(null, { push, loginUser, setReviewerPassword, reviewerDecision }), lifecycle({ componentDidMount() { - // 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 (agree === 'true') { - // setReviewer(reviewerBody) - // } else { - // reviewerDecision(invitationId, collectionId, false) - // } - // console.log('rev sign up mounted?', this.props) + const { + agree, + email, + setEmail, + collectionId, + invitationId, + reviewerDecision, + } = this.props + setEmail(email) + + if (agree === 'false') { + reviewerDecision(invitationId, collectionId, false) + } }, }), reduxForm({ @@ -99,22 +92,25 @@ export default compose( dispatch, { push, - loginUser, - searchParams, - reviewer, + email, + token, location, + loginUser, + fragmentId, + collectionId, + invitationId, setReviewerPassword, }, - ) => { - const { collectionId, fragmentId, agree, invitationId } = searchParams - return setReviewerPassword({ - ...reviewer, + ) => + setReviewerPassword({ + email, + token, password, }) .then(() => { loginUser( - { username: reviewer.email, password }, - `/projects/${collectionId}/versions/${fragmentId}/details?agree=${agree}&invitationId=${invitationId}`, + { username: email, password }, + `/projects/${collectionId}/versions/${fragmentId}/details?agree=${true}&invitationId=${invitationId}`, ) }) .catch(error => { @@ -125,7 +121,6 @@ export default compose( _error: errorMessage || 'Something went wrong', }) } - }) - }, + }), }), -)(ReviewerSignUp) +)(ReviewerInviteDecision) diff --git a/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js b/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js index 671d99d58832bff7eded4b4ce256f1f9c61c82a3..d1771f7bd0d2b930677b232ff559ffd619df1e78 100644 --- a/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js +++ b/packages/components-faraday/src/components/SignUp/ReviewerSignUp.js @@ -1,27 +1,39 @@ import React from 'react' +import { isEmpty } from 'lodash' import { Route } from 'react-router-dom' import { AuthenticatedComponent } from 'pubsweet-client' -import { ReviewerAgree, ReviewerDecline } from './' +import { ReviewerInviteDecision, ReviewerDecline } from './' import { parseSearchParams } from './utils' -const PrivateRoute = ({ component: Component, ...rest }) => ( +const PrivateRoute = ({ component: Component, token, ...rest }) => ( <Route - {...rest} - render={props => ( - <AuthenticatedComponent> - <Component {...props} /> - </AuthenticatedComponent> - )} + render={props => + isEmpty(token) ? ( + <AuthenticatedComponent> + <Component {...props} {...rest} /> + </AuthenticatedComponent> + ) : ( + <Component {...props} {...rest} token={token} /> + ) + } /> ) const ReviewerSignUp = ({ location }) => { - const { agree } = parseSearchParams(location.search) - return agree === 'true' ? ( - <PrivateRoute component={ReviewerAgree} /> + const { invitationToken, ...rest } = parseSearchParams(location.search) + return isEmpty(invitationToken) ? ( + <PrivateRoute component={ReviewerInviteDecision} {...rest} /> ) : ( - <Route component={ReviewerDecline} /> + <Route + component={props => ( + <ReviewerDecline + {...props} + invitationToken={invitationToken} + {...rest} + /> + )} + /> ) } diff --git a/packages/components-faraday/src/components/SignUp/index.js b/packages/components-faraday/src/components/SignUp/index.js index 21a5cd8e67d2630a46ae338afa7d6d297179544b..8fc6a0dd3bbf70231a30792e4d78aa5594d848f4 100644 --- a/packages/components-faraday/src/components/SignUp/index.js +++ b/packages/components-faraday/src/components/SignUp/index.js @@ -1,4 +1,4 @@ -export { default as ReviewerAgree } from './ReviewerAgree' export { default as ReviewerSignUp } from './ReviewerSignUp' export { default as ReviewerDecline } from './ReviewerDecline' export { default as SignUpInvitationPage } from './SignUpInvitationPage' +export { default as ReviewerInviteDecision } from './ReviewerInviteDecision' diff --git a/packages/components-faraday/src/redux/reviewers.js b/packages/components-faraday/src/redux/reviewers.js index 1a7cd50047480605f1e5f38995f98d1acad7c9b8..7f5795c31c0b0e3148692c58b725eb3d6ac6d031 100644 --- a/packages/components-faraday/src/redux/reviewers.js +++ b/packages/components-faraday/src/redux/reviewers.js @@ -132,7 +132,30 @@ export const reviewerDecision = ( }, err => { dispatch(reviewerDecisionError(err.message)) - return err + throw err + }, + ) +} + +export const reviewerDecline = ( + invitationId, + collectionId, + invitationToken, +) => dispatch => { + dispatch(reviewerDecisionRequest()) + return update( + `/collections/${collectionId}/invitations/${invitationId}/decline`, + { + invitationToken, + }, + ).then( + res => { + dispatch(reviewerDecisionSuccess()) + return res + }, + err => { + dispatch(reviewerDecisionError(err.message)) + throw err }, ) }