Skip to content
Snippets Groups Projects
Commit f1143360 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

refactor(details): refact reviewers resend/revoke

parent 0ed5c0c5
No related branches found
No related tags found
1 merge request!8Sprint #10
...@@ -5,7 +5,7 @@ import styled from 'styled-components' ...@@ -5,7 +5,7 @@ import styled from 'styled-components'
import { compose, withHandlers, lifecycle } from 'recompose' import { compose, withHandlers, lifecycle } from 'recompose'
import { ReviewerBreakdown } from 'pubsweet-components-faraday/src/components/Invitations' import { ReviewerBreakdown } from 'pubsweet-components-faraday/src/components/Invitations'
import { ReviewersList } from 'pubsweet-components-faraday/src/components/Reviewers' import ReviewersDetailsList from 'pubsweet-components-faraday/src/components/Reviewers/ReviewersDetailsList'
import { import {
selectReviewers, selectReviewers,
selectFetchingReviewers, selectFetchingReviewers,
...@@ -20,7 +20,7 @@ const getTabSections = (collectionId, reviewers) => [ ...@@ -20,7 +20,7 @@ const getTabSections = (collectionId, reviewers) => [
key: 1, key: 1,
label: 'Reviewers Details', label: 'Reviewers Details',
content: ( content: (
<ReviewersList collectionId={collectionId} reviewers={reviewers} /> <ReviewersDetailsList collectionId={collectionId} reviewers={reviewers} />
), ),
}, },
{ {
......
...@@ -5,8 +5,17 @@ import { connect } from 'react-redux' ...@@ -5,8 +5,17 @@ import { connect } from 'react-redux'
import { th, Icon } from '@pubsweet/ui' import { th, Icon } from '@pubsweet/ui'
import styled, { withTheme } from 'styled-components' import styled, { withTheme } from 'styled-components'
import { compose, withHandlers, withProps } from 'recompose' import { compose, withHandlers, withProps } from 'recompose'
import {
import { revokeReviewer, inviteReviewer } from '../../redux/reviewers' ConfirmationModal,
withModal2,
} from 'pubsweet-component-modal/src/components'
import {
revokeReviewer,
inviteReviewer,
selectFetchingInvite,
selectReviewersError,
} from '../../redux/reviewers'
const ResendRevoke = withTheme( const ResendRevoke = withTheme(
({ theme, showConfirmResend, showConfirmRevoke, status }) => ( ({ theme, showConfirmResend, showConfirmRevoke, status }) => (
...@@ -23,7 +32,7 @@ const ResendRevoke = withTheme( ...@@ -23,7 +32,7 @@ const ResendRevoke = withTheme(
), ),
) )
const ReviewersList = ({ const ReviewersDetailsList = ({
renderAcceptedLabel, renderAcceptedLabel,
reviewers, reviewers,
showConfirmResend, showConfirmResend,
...@@ -65,8 +74,20 @@ const ReviewersList = ({ ...@@ -65,8 +74,20 @@ const ReviewersList = ({
</Root> </Root>
) )
const ModalWrapper = compose(
connect(state => ({
fetchingInvite: selectFetchingInvite(state),
modalError: selectReviewersError(state),
})),
)(({ fetchingInvite, ...rest }) => (
<ConfirmationModal {...rest} isFetching={fetchingInvite} />
))
export default compose( export default compose(
connect(null, { inviteReviewer, revokeReviewer }), connect(null, { inviteReviewer, revokeReviewer }),
withModal2(props => ({
modalComponent: ModalWrapper,
})),
withProps(({ reviewers = [] }) => ({ withProps(({ reviewers = [] }) => ({
firstAccepted: reviewers.findIndex(r => r.status === 'accepted'), firstAccepted: reviewers.findIndex(r => r.status === 'accepted'),
})), })),
...@@ -81,21 +102,14 @@ export default compose( ...@@ -81,21 +102,14 @@ export default compose(
} }
return stamp.format('DD.MM.YYYY') return stamp.format('DD.MM.YYYY')
}, },
goBackToReviewers: ({ showModal, hideModal, collectionId }) => () => {
showModal({
collectionId,
type: 'invite-reviewers',
onConfirm: () => {
hideModal()
},
})
},
renderAcceptedLabel: ({ firstAccepted }) => index => renderAcceptedLabel: ({ firstAccepted }) => index =>
`Reviewer ${index - firstAccepted + 1}`, `Reviewer ${index - firstAccepted + 1}`,
}), }),
withHandlers({ withHandlers({
showConfirmResend: ({ showConfirmResend: ({
showModal, showModal,
hideModal,
setModalError,
goBackToReviewers, goBackToReviewers,
inviteReviewer, inviteReviewer,
collectionId, collectionId,
...@@ -107,14 +121,15 @@ export default compose( ...@@ -107,14 +121,15 @@ export default compose(
inviteReviewer( inviteReviewer(
pick(reviewer, ['email', 'firstName', 'lastName', 'affiliation']), pick(reviewer, ['email', 'firstName', 'lastName', 'affiliation']),
collectionId, collectionId,
).then(goBackToReviewers, goBackToReviewers) ).then(hideModal)
}, },
onCancel: goBackToReviewers, onCancel: hideModal,
}) })
}, },
showConfirmRevoke: ({ showConfirmRevoke: ({
showModal, showModal,
hideModal, hideModal,
setModalError,
goBackToReviewers, goBackToReviewers,
revokeReviewer, revokeReviewer,
collectionId, collectionId,
...@@ -123,16 +138,13 @@ export default compose( ...@@ -123,16 +138,13 @@ export default compose(
title: 'Unassign Reviewer', title: 'Unassign Reviewer',
confirmText: 'Unassign', confirmText: 'Unassign',
onConfirm: () => { onConfirm: () => {
revokeReviewer(invitationId, collectionId).then( revokeReviewer(invitationId, collectionId).then(hideModal)
goBackToReviewers,
goBackToReviewers,
)
}, },
onCancel: goBackToReviewers, onCancel: hideModal,
}) })
}, },
}), }),
)(ReviewersList) )(ReviewersDetailsList)
// #region styled-components // #region styled-components
const ReviewerEmail = styled.span` const ReviewerEmail = styled.span`
......
...@@ -106,7 +106,10 @@ export const inviteReviewer = (reviewerData, collectionId) => dispatch => { ...@@ -106,7 +106,10 @@ export const inviteReviewer = (reviewerData, collectionId) => dispatch => {
role: 'reviewer', role: 'reviewer',
}).then( }).then(
() => dispatch(inviteSuccess()), () => dispatch(inviteSuccess()),
err => dispatch(inviteError(get(JSON.parse(err.response), 'error'))), err => {
dispatch(inviteError(get(JSON.parse(err.response), 'error')))
throw err
},
) )
} }
...@@ -124,7 +127,10 @@ export const revokeReviewer = (invitationId, collectionId) => dispatch => { ...@@ -124,7 +127,10 @@ export const revokeReviewer = (invitationId, collectionId) => dispatch => {
`/collections/${collectionId}/invitations/${invitationId}`, `/collections/${collectionId}/invitations/${invitationId}`,
).then( ).then(
() => dispatch(inviteSuccess()), () => dispatch(inviteSuccess()),
err => dispatch(inviteError(get(JSON.parse(err.response), 'error'))), err => {
dispatch(inviteError(get(JSON.parse(err.response), 'error')))
throw err
},
) )
} }
......
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