Skip to content
Snippets Groups Projects
Commit bd1d59a4 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

feat(email-errors): handle errors after clicking on email buttons

parent bed9cc71
No related branches found
No related tags found
1 merge request!6Agree/Decline to work on a manuscript
...@@ -10,7 +10,7 @@ import { replace } from 'react-router-redux' ...@@ -10,7 +10,7 @@ import { replace } from 'react-router-redux'
import { compose, lifecycle, withHandlers } from 'recompose' import { compose, lifecycle, withHandlers } from 'recompose'
import ManuscriptLayout from './ManuscriptLayout' import ManuscriptLayout from './ManuscriptLayout'
import { parseSearchParams } from './utils' import { parseSearchParams, redirectToError } from './utils'
import { reviewerDecision } from '../../../components-faraday/src/redux/reviewers' import { reviewerDecision } from '../../../components-faraday/src/redux/reviewers'
export default compose( export default compose(
...@@ -35,8 +35,10 @@ export default compose( ...@@ -35,8 +35,10 @@ export default compose(
const collectionId = match.params.project const collectionId = match.params.project
const { agree, invitationId } = parseSearchParams(location.search) const { agree, invitationId } = parseSearchParams(location.search)
if (agree === 'true') { if (agree === 'true') {
reviewerDecision(invitationId, collectionId, true)
replace(location.pathname) replace(location.pathname)
reviewerDecision(invitationId, collectionId, true).catch(
redirectToError(replace),
)
} }
}, },
}), }),
......
/* eslint-disable */ /* eslint-disable */
import { get } from 'lodash'
export const parseSearchParams = url => { export const parseSearchParams = url => {
const params = new URLSearchParams(url) const params = new URLSearchParams(url)
...@@ -8,3 +9,13 @@ export const parseSearchParams = url => { ...@@ -8,3 +9,13 @@ export const parseSearchParams = url => {
} }
return parsedObject return parsedObject
} }
const alreadyAnswered = `You have already answered this invitation.`
export const redirectToError = redirectFn => err => {
const errorText = get(JSON.parse(err.response), 'error')
if (errorText.includes('has already been answered')) {
redirectFn('/error-page', alreadyAnswered)
} else {
redirectFn('/error-page', 'Oops! Something went wrong.')
}
}
import React from 'react' import React from 'react'
import { get } from 'lodash' import { get } from 'lodash'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { push } from 'react-router-redux' import { push, replace } from 'react-router-redux'
import { required, minChars } from 'xpub-validators' import { required, minChars } from 'xpub-validators'
import { reduxForm, SubmissionError } from 'redux-form' import { reduxForm, SubmissionError } from 'redux-form'
import { compose, withState, lifecycle } from 'recompose'
import { loginUser } from 'pubsweet-component-login/actions' import { loginUser } from 'pubsweet-component-login/actions'
import { Button, ValidatedField, TextField } from '@pubsweet/ui' import { Button, ValidatedField, TextField } from '@pubsweet/ui'
import { compose, withState, lifecycle, withHandlers } from 'recompose'
import { import {
Row, Row,
...@@ -20,23 +20,22 @@ import { ...@@ -20,23 +20,22 @@ import {
FormContainer, FormContainer,
} from './FormItems' } from './FormItems'
import { reviewerDecision, setReviewerPassword } from '../../redux/reviewers' import { reviewerDecision, setReviewerPassword } from '../../redux/reviewers'
import { redirectToError } from '../utils'
const agreeText = `You have been invited to review a manuscript on the Hindawi platform. Please set a password and proceed to the manuscript.` const agreeText = `You have been invited to review a manuscript on the Hindawi platform. Please set a password and proceed to the manuscript.`
const declineText = `You have decline to work on a manuscript.` const declineText = `You have decline to work on a manuscript.`
const alreadyDeclined = `You have already declined to work on this manuscript.`
const min8Chars = minChars(8) const min8Chars = minChars(8)
const ReviewerInviteDecision = ({ const ReviewerInviteDecision = ({
handleSubmit, agree,
error, error,
handleSubmit,
reviewerEmail, reviewerEmail,
agree,
errorMessage, errorMessage,
renderSubtitle,
}) => ( }) => (
<RootContainer> <RootContainer>
<Title>Hindawi Invitation</Title> <Title>Hindawi Invitation</Title>
<Subtitle>{renderSubtitle()}</Subtitle> <Subtitle>{agree === 'true' ? agreeText : declineText}</Subtitle>
<Email>{reviewerEmail}</Email> <Email>{reviewerEmail}</Email>
{agree === 'true' && ( {agree === 'true' && (
<FormContainer onSubmit={handleSubmit}> <FormContainer onSubmit={handleSubmit}>
...@@ -68,15 +67,20 @@ const ReviewerInviteDecision = ({ ...@@ -68,15 +67,20 @@ const ReviewerInviteDecision = ({
) )
export default compose( export default compose(
withState('errorMessage', 'setError', ''),
withState('reviewerEmail', 'setEmail', ''), withState('reviewerEmail', 'setEmail', ''),
connect(null, { push, loginUser, setReviewerPassword, reviewerDecision }), connect(null, {
push,
replace,
loginUser,
setReviewerPassword,
reviewerDecision,
}),
lifecycle({ lifecycle({
componentDidMount() { componentDidMount() {
const { const {
agree, agree,
email, email,
setError, replace,
setEmail, setEmail,
collectionId, collectionId,
invitationId, invitationId,
...@@ -85,26 +89,10 @@ export default compose( ...@@ -85,26 +89,10 @@ export default compose(
setEmail(email) setEmail(email)
if (agree === 'false') { if (agree === 'false') {
reviewerDecision(invitationId, collectionId, false).catch(err => { reviewerDecision(invitationId, collectionId, false).catch(
const errorText = get(JSON.parse(err.response), 'error') redirectToError(replace),
if (errorText.includes('has already been answered')) { )
setError(alreadyDeclined)
} else {
setError('Oops! Something went wrong.')
}
})
}
},
}),
withHandlers({
renderSubtitle: ({ agree, errorMessage }) => () => {
if (agree === 'true') {
return agreeText
}
if (errorMessage) {
return errorMessage
} }
return declineText
}, },
}), }),
reduxForm({ reduxForm({
......
import React from 'react'
import { Button } from '@pubsweet/ui'
import styled from 'styled-components'
const ErrorPage = ({ location: { state }, history }) => (
<Root>
<Title>{state}</Title>
<Button onClick={() => history.push('/')} primary>
Go to Dashboard
</Button>
</Root>
)
export default ErrorPage
// #region styles
const Root = styled.div`
margin: 0 auto;
text-align: center;
width: 70vw;
color: ${({ theme }) => theme.colorText};
a {
color: ${({ theme }) => theme.colorText};
}
`
const Title = styled.div`
font-size: ${({ theme }) => theme.fontSizeHeading5};
font-family: ${({ theme }) => theme.fontHeading};
color: ${({ theme }) => theme.colorPrimary};
margin: 10px auto;
`
// #endregion
export { default as Logo } from './Logo' export { default as Logo } from './Logo'
export { default as Spinner } from './Spinner' export { default as Spinner } from './Spinner'
export { default as NotFound } from './NotFound'
export { default as Dropdown } from './Dropdown' export { default as Dropdown } from './Dropdown'
export { default as ErrorPage } from './ErrorPage'
export { default as ConfirmationPage } from './ConfirmationPage'
...@@ -75,3 +75,13 @@ const emailRegex = new RegExp( ...@@ -75,3 +75,13 @@ const emailRegex = new RegExp(
export const emailValidator = value => export const emailValidator = value =>
emailRegex.test(value) ? undefined : 'Invalid email' emailRegex.test(value) ? undefined : 'Invalid email'
const alreadyAnswered = `You have already answered this invitation.`
export const redirectToError = redirectFn => err => {
const errorText = get(JSON.parse(err.response), 'error')
if (errorText.includes('has already been answered')) {
redirectFn('/error-page', alreadyAnswered)
} else {
redirectFn('/error-page', 'Oops! Something went wrong.')
}
}
...@@ -8,8 +8,11 @@ import Signup from 'pubsweet-component-signup/SignupContainer' ...@@ -8,8 +8,11 @@ import Signup from 'pubsweet-component-signup/SignupContainer'
import { Wizard } from 'pubsweet-component-wizard/src/components' import { Wizard } from 'pubsweet-component-wizard/src/components'
import { ManuscriptPage } from 'pubsweet-component-manuscript/src/components' import { ManuscriptPage } from 'pubsweet-component-manuscript/src/components'
import DashboardPage from 'pubsweet-components-faraday/src/components/Dashboard' import DashboardPage from 'pubsweet-components-faraday/src/components/Dashboard'
import NotFound from 'pubsweet-components-faraday/src/components/UIComponents/NotFound' import {
import ConfirmationPage from 'pubsweet-components-faraday/src/components/UIComponents/ConfirmationPage' NotFound,
ConfirmationPage,
ErrorPage,
} from 'pubsweet-components-faraday/src/components/UIComponents/'
import { import {
AdminDashboard, AdminDashboard,
AdminUsers, AdminUsers,
...@@ -67,6 +70,8 @@ const Routes = () => ( ...@@ -67,6 +70,8 @@ const Routes = () => (
exact exact
path="/projects/:project/versions/:version/details" path="/projects/:project/versions/:version/details"
/> />
<Route component={ErrorPage} exact path="/error-page" />
<Route component={NotFound} /> <Route component={NotFound} />
</Switch> </Switch>
</FaradayApp> </FaradayApp>
......
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