Starting from Monday (10th of May 2021), 2 Factor Authentication enforcement will be enabled. If 2FA is not configured within 48h, you will not be able to perform any action on GitLab until 2FA is configured. Please click here to learn how to do that.

Commit 9491272c authored by Alf Eaton's avatar Alf Eaton
Browse files

Refactor submit form

parent ec3e3a70
import React from 'react'
import classnames from 'classnames'
import { Link } from 'react-router'
import { Button } from 'xpub-ui'
import Metadata from './Metadata'
import Declarations from './Declarations'
import Suggestions from './Suggestions'
import Notes from './Notes'
import SupplementaryFiles from './SupplementaryFiles'
import Confirm from './Confirm'
import Validots from './Validots'
import SubmitFormContainer from './SubmitFormContainer'
import classes from './Submit.local.scss'
const Submit = ({ project, version, valid, pristine, submitting, handleSubmit, uploadFile, confirming, toggleConfirming }) => (
const Submit = ({ project, version, confirming, toggleConfirming }) => (
<div className={classnames(classes.root, {
[classes.confirming]: confirming
})}>
......@@ -25,35 +19,15 @@ const Submit = ({ project, version, valid, pristine, submitting, handleSubmit, u
<div>The answers will be automatically saved.</div>
</div>
<form onSubmit={handleSubmit}>
<Metadata/>
<Declarations/>
<Suggestions/>
<Notes/>
<SupplementaryFiles uploadFile={uploadFile}/>
<SubmitFormContainer
version={version}
toggleConfirming={toggleConfirming}/>
<div>
<Button
type="button"
primary
onClick={toggleConfirming}
disabled={submitting || !valid}>
Submit your manuscript
</Button>
{confirming && (
<div className={classes.confirm}>
<Confirm toggleConfirming={toggleConfirming}/>
</div>
{confirming && (
<div className={classes.confirm}>
<Confirm toggleConfirming={toggleConfirming}/>
</div>
)}
</form>
<div className={classes.validots}>
<Validots
valid={valid}
handleSubmit={handleSubmit}/>
</div>
)}
</div>
)
......
......@@ -24,8 +24,3 @@
overflow: hidden;
}
.validots {
position: absolute;
top: 50px;
right: 10px;
}
import React from 'react'
import { Button } from 'xpub-ui'
import Metadata from './Metadata'
import Declarations from './Declarations'
import Suggestions from './Suggestions'
import Notes from './Notes'
import SupplementaryFiles from './SupplementaryFiles'
// import Validots from './Validots'
// import classes from './SubmitForm.local.scss'
const SubmitForm = ({ valid, handleSubmit, confirming, toggleConfirming, uploadFile }) => (
<form onSubmit={handleSubmit}>
<Metadata/>
<Declarations/>
<Suggestions/>
<Notes/>
<SupplementaryFiles uploadFile={uploadFile}/>
<div>
<Button
type="button"
primary
onClick={toggleConfirming}
disabled={!valid}>
Submit your manuscript
</Button>
</div>
{/*<div className={classes.validots}>
<Validots
valid={valid}
handleSubmit={handleSubmit}/>
</div>*/}
</form>
)
export default SubmitForm
.validots {
position: absolute;
top: 50px;
right: 10px;
}
import { pick } from 'lodash'
import { compose, withProps } from 'recompose'
import { connect } from 'react-redux'
import { push } from 'react-router-redux'
import { reduxForm, SubmissionError } from 'redux-form'
import uploadFile from 'xpub-upload'
import actions from 'pubsweet-client/src/actions'
import SubmitForm from './SubmitForm'
const onSubmit = (values, dispatch, props) => {
console.log('submit', values)
return dispatch(actions.updateFragment(props.project, {
id: props.version.id,
submitted: true,
...values
})).then(() => {
return dispatch(actions.updateCollection({
id: props.project.id,
status: 'submitted'
}))
}).then(() => {
dispatch(push(`/`))
}).catch(error => {
if (error.validationErrors) {
throw new SubmissionError()
}
})
}
// TODO: redux-form doesn't have an onBlur handler(?)
const onBlur = (values, dispatch, props) => {
console.log('change', values)
return dispatch(actions.updateFragment(props.project, {
id: props.version.id,
// submitted: false,
...values
}))
// TODO: display a notification when saving/saving completes/saving fails
}
export default compose(
connect(
null,
{
uploadFile
}
),
withProps(({version}) => {
const paths = ['metadata', 'declarations', 'suggestions', 'notes', 'files']
return {
initialValues: pick(version, paths),
}
}),
reduxForm({
form: 'submit',
// enableReinitialize: true,
// keepDirtyOnReinitialize: true,
onSubmit,
onBlur
})
)(SubmitForm)
import { pick } from 'lodash'
import { compose, withProps, withState, withHandlers } from 'recompose'
import { connect } from 'react-redux'
import { push } from 'react-router-redux'
import { reduxForm, SubmissionError } from 'redux-form'
import { compose, withState, withHandlers } from 'recompose'
import actions from 'pubsweet-client/src/actions'
import uploadFile from 'xpub-upload'
import { ConnectPage } from 'xpub-connect'
import { selectCollection, selectFragment } from 'xpub-selectors'
import Submit from './Submit'
const onSubmit = (values, dispatch, props) => {
console.log('submit', values)
return dispatch(actions.updateFragment(props.project, {
id: props.version.id,
submitted: true,
...values
})).then(() => {
return dispatch(actions.updateCollection({
id: props.project.id,
status: 'submitted'
}))
}).then(() => {
dispatch(push(`/`))
}).catch(error => {
if (error.validationErrors) {
throw new SubmissionError()
}
})
}
// TODO: redux-form doesn't have an onBlur handler(?)
const onBlur = (values, dispatch, props) => {
console.log('change', values)
return dispatch(actions.updateFragment(props.project, {
id: props.version.id,
// submitted: false,
...values
}))
// TODO: display a notification when saving/saving completes/saving fails
}
export default compose(
ConnectPage(({ params }) => [
actions.getCollection({ id: params.project }),
......@@ -52,24 +14,8 @@ export default compose(
(state, ownProps) => ({
project: selectCollection(state, ownProps.params.project),
version: selectFragment(state, ownProps.params.version)
}),
{
uploadFile
}
})
),
withProps(({ version }) => {
const paths = ['metadata', 'declarations', 'suggestions', 'notes', 'files']
return {
initialValues: pick(version, paths)
}
}),
reduxForm({
form: 'submit',
// enableReinitialize: true,
onSubmit,
onBlur
}),
withState('confirming', 'setConfirming', false),
withHandlers({
toggleConfirming: props => () => {
......
Markdown is supported
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