Newer
Older

Daniel Sandu
committed
import { pick } from 'lodash'
import { withHandlers, withProps, compose } from 'recompose'
import { handleError, withFetching } from 'pubsweet-component-faraday-ui'
import { parseEicDecision } from './utils'
import { createRecommendation } from './handleRecommendation.api'
export default compose(
withFetching,
withHandlers({
createRecommendation: ({
fragment,
collection,
fetchUpdatedCollection,
}) => (values, modalProps) => {
const recommendation = parseEicDecision(values)
modalProps.setFetching(true)
createRecommendation({
recommendation,
fragmentId: fragment.id,
collectionId: collection.id,
})
.then(() => {
modalProps.setFetching(false)
modalProps.hideModal()
fetchUpdatedCollection()
})
.catch(err => {
modalProps.setFetching(false)
handleError(modalProps.setModalError)(err)
})
},
onEditorialRecommendation: ({
fragment,
collection,
fetchUpdatedCollection,

Mihail Hagiu
committed
}) => (
recommendation,
{ hideModal, setFetching, setModalError, reset },
) => {

Daniel Sandu
committed
setFetching(true)
createRecommendation({
recommendation,
fragmentId: fragment.id,
collectionId: collection.id,
})
.then(r => {
setFetching(false)

Mihail Hagiu
committed
reset()

Daniel Sandu
committed
hideModal()
fetchUpdatedCollection()
})
.catch(e => {
setFetching(false)
handleError(setModalError)(e)
})
},
}),
withProps(props => ({

Daniel Sandu
committed
...pick(props, ['createRecommendation', 'onEditorialRecommendation']),
},
})),
)