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

feat(SubmitRevision): create submit revision hoc

parent 13fbcae2
No related branches found
No related tags found
3 merge requests!108Hin 858 revision fix,!106Hin 858,!97HIN-858
import { withProps } from 'recompose'
import countrylist from 'country-list'
const countryMapper = c => {
const countryMapper = (c = 'RO') => {
switch (c) {
case 'GB':
return 'UK'
......@@ -14,7 +14,7 @@ const countryMapper = c => {
}
}
const codeMapper = c => {
const codeMapper = (c = 'RO') => {
switch (c) {
case 'UK':
return 'GB'
......
import React from 'react'
import { FilePicker } from '@pubsweet/ui'
import { isEmpty } from 'lodash'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { FilePicker, ValidatedField } from '@pubsweet/ui'
import {
Row,
Item,
Textarea,
ActionLink,
} from 'pubsweet-component-faraday-ui/src'
import styled from 'styled-components'
import { ContextualBox, Label } from '../'
const ResponseToReviewer = ({ allowedFileExtensions, onUpload }) => (
import {
Label,
FileItem,
ContextualBox,
ItemOverrideAlert,
withFilePreview,
withFileDownload,
} from '../'
const ResponseToReviewer = ({
file,
onDelete,
onUpload,
previewFile,
downloadFile,
}) => (
<ContextualBox
label="Response to Reviewer Comments"
mt={1}
startExpanded
transparent
>
......@@ -21,16 +38,36 @@ const ResponseToReviewer = ({ allowedFileExtensions, onUpload }) => (
<Item>
<Label required>Your Reply</Label>
<FilePicker
allowedFileExtensions={allowedFileExtensions}
allowedFileExtensions={['pdf', 'doc', 'docx', 'txt', 'rdf', 'odt']}
disabled={!isEmpty(file)}
onUpload={onUpload}
>
<ActionLink icon="plus">UPLOAD FILE</ActionLink>
<ActionLink disabled={!isEmpty(file)} icon="plus">
UPLOAD FILE
</ActionLink>
</FilePicker>
</Item>
</Row>
<Row>
<Textarea />
<ItemOverrideAlert vertical>
<ValidatedField
component={Textarea}
name="responseToReviewers.content"
/>
</ItemOverrideAlert>
</Row>
{!isEmpty(file) && (
<Row justify="flex-start" mt={1}>
<FileItem
item={file}
onDelete={onDelete}
onDownload={f => downloadFile(f)}
onPreview={f => previewFile(f)}
/>
</Row>
)}
</Root>
</ContextualBox>
)
......@@ -40,4 +77,4 @@ const Root = styled.div`
padding-left: calc(${th('gridUnit')} * 1);
`
export default ResponseToReviewer
export default withFileDownload(withFilePreview(ResponseToReviewer))
import React from 'react'
import { connect } from 'react-redux'
import { compose, withHandlers, toClass } from 'recompose'
import { reduxForm, change as changeForm } from 'redux-form'
import { DragDropContext } from 'react-dnd'
import { Button } from '@pubsweet/ui'
import styled from 'styled-components'
import HTML5Backend from 'react-dnd-html5-backend'
import { th } from '@pubsweet/ui-toolkit'
import { Button } from '@pubsweet/ui'
import { DragDropContext } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import { Row } from 'pubsweet-component-faraday-ui/src'
import { compose, withHandlers, toClass } from 'recompose'
import { reduxForm, change as changeForm } from 'redux-form'
import { ManuscriptFiles, DetailsAndAuthors, ResponseToReviewer } from './'
import { ContextualBox } from '../'
import { ManuscriptFiles, DetailsAndAuthors, ResponseToReviewer } from './'
const SubmitRevision = ({
journal,
fragment,
collection,
changeForm,
currentUser,
handleSubmit,
onAuthorEdit,
responseFile,
deleteFile,
getSignedUrl,
addResponseFile,
addAuthor = () => Promise.resolve(42),
uploadFile = ({ file }) => Promise.resolve(file),
}) => (
......@@ -32,13 +37,22 @@ const SubmitRevision = ({
manuscriptTypes={journal.manuscriptTypes}
onAuthorEdit={onAuthorEdit}
/>
<ManuscriptFiles
collection={collection}
formName="revision"
fragment={fragment}
uploadFile={uploadFile}
/>
<ResponseToReviewer />
<ResponseToReviewer
file={responseFile}
getSignedUrl={getSignedUrl}
onDelete={deleteFile}
onUpload={addResponseFile}
token={currentUser.token}
/>
<Row justify="flex-end" mt={1}>
<Button onClick={() => null} secondary size="medium">
Reset changes
......
......@@ -72,6 +72,7 @@ const ManuscriptLayout = ({
toggleReviewerDetails,
reviewerDetailsExpanded,
onInvitePublonReviewer,
submitRevision,
}) => (
<Root pb={30}>
{!isEmpty(collection) && !isEmpty(fragment) ? (
......@@ -103,11 +104,7 @@ const ManuscriptLayout = ({
getSignedUrl={getSignedUrl}
/>
<SubmitRevision
collection={collection}
fragment={fragment}
journal={journal}
/>
<SubmitRevision {...submitRevision} />
{get(currentUser, 'permissions.canViewReports', true) &&
!!editorialRecommendations.length && (
......
......@@ -63,6 +63,7 @@ import {
} from 'pubsweet-component-faraday-ui'
import ManuscriptLayout from './ManuscriptLayout'
import withSubmitRevision from '../submitRevision/withSubmitRevision'
import {
parseEicDecision,
parseSearchParams,
......@@ -180,6 +181,7 @@ export default compose(
publonsFetching: isFetching,
},
formValues: {
revision: getFormValues('revision')(state),
eicDecision: getFormValues('eic-decision')(state),
reviewerReport: getFormValues('reviewerReport')(state),
responseToInvitation: getFormValues('answer-invitation')(state),
......@@ -479,6 +481,7 @@ export default compose(
get(currentUser, 'isReviewer', false) &&
isUndefined(submittedOwnRecommendation),
})),
withSubmitRevision,
lifecycle({
componentDidMount() {
const {
......
import { actions } from 'pubsweet-client'
import { get, debounce, omit, mergeWith } from 'lodash'
import { autosaveRequest } from 'pubsweet-component-wizard/src/redux/autosave'
const parseRevision = (values, fragment) => {
const v = omit(values, 'authorForm')
return {
...fragment,
revision: {
...v,
metadata: mergeWith(
{},
fragment.metadata,
v.metadata,
(obj, src) => (src === '' ? obj : src),
),
},
}
}
const _onChange = (values, dispatch, { collection, fragment }) => {
dispatch(autosaveRequest())
dispatch(actions.updateFragment(collection, parseRevision(values, fragment)))
}
export const onChange = debounce(_onChange, 1000, { maxWait: 5000 })
export const onSubmit = (values, dispatch, { fragment, collection }) => {
// dispatch(
// actions.updateFragment(collection, {
// ...fragment,
// revision,
// }),
// )
// console.log('se face surmit', values)
}
export const getInitialValues = fragment => ({
files: get(fragment, 'revision.files', {}),
authors: get(fragment, 'revision.authors', []),
metadata: get(fragment, 'revision.metadata', {
abstract: '',
title: '',
type: '',
}),
responseToReviewers: get(fragment, 'revision.responseToReviewers', {
content: '',
file: null,
}),
})
import { get } from 'lodash'
import { compose, withHandlers, withProps } from 'recompose'
import {
uploadFile,
deleteFile,
} from 'pubsweet-components-faraday/src/redux/files'
import { onChange, onSubmit, getInitialValues } from './utils'
export default compose(
withHandlers({
addResponseFile: ({ fragment, changeForm }) => file =>
uploadFile({
file,
fragment,
type: 'responseToReviewers',
}).then(f => {
changeForm('revision', 'responseToReviewers.file', f)
}),
deleteFile: ({ changeForm }) => file =>
deleteFile(file.id, 'responseToReviewers').then(r => {
changeForm('revision', 'responseToReviewers.file', null)
}),
}),
withProps(
({
journal,
fragment,
deleteFile,
collection,
currentUser,
getSignedUrl,
addResponseFile,
formValues: { revision },
}) => ({
submitRevision: {
journal,
onChange,
fragment,
onSubmit,
collection,
deleteFile,
currentUser,
getSignedUrl,
addResponseFile,
initialValues: getInitialValues(fragment),
responseFile: get(revision, 'responseToReviewers.file', null),
},
}),
),
)
......@@ -28,6 +28,8 @@ export const getAutosave = state => get(state, 'autosave', initialState)
export const getAutosaveFetching = state =>
get(state, 'autosave.isFetching', false)
// due to faulty error handing inside the updateFragment action, we have to
// handle error and success here
export default (state = initialState, action) => {
switch (action.type) {
case AUTOSAVE_REQUEST:
......@@ -35,11 +37,13 @@ export default (state = initialState, action) => {
...initialState,
isFetching: true,
}
case 'UPDATE_FRAGMENT_FAILURE':
case AUTOSAVE_FAILURE:
return {
...initialState,
error: action.error,
}
case 'UPDATE_FRAGMENT_SUCCESS':
case AUTOSAVE_SUCCESS:
return {
...initialState,
......
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