Skip to content
Snippets Groups Projects
Commit 20ebb358 authored by Sam Galson's avatar Sam Galson Committed by Mihail Dunaev
Browse files

feat(submission): continue wiring up form

parent 9b268fbd
No related branches found
No related tags found
1 merge request!29Get current ms
......@@ -24,12 +24,12 @@ class AuthorDetails extends React.Component {
}
openCorrespondentForm() {
this.props.setFieldValue('displayCorrespondent', true)
this.props.setFieldValue('submissionMeta.displayCorrespondent', true)
}
closeCorrespondentForm() {
this.props.setFieldValue('correspondent', emptyPerson)
this.props.setFieldValue('displayCorrespondent', false)
this.props.setFieldTouched('correspondent', false)
this.props.setFieldValue('submissionMeta.correspondent', emptyPerson)
this.props.setFieldValue('submissionMeta.displayCorrespondent', false)
this.props.setFieldTouched('submissionMeta.correspondent', false)
}
handleNotCorrespondingAuthor() {
......@@ -41,7 +41,7 @@ class AuthorDetails extends React.Component {
}
render() {
const { handleSubmit } = this.props
const { handleSubmit, values /* errors */ } = this.props
return (
<form noValidate onSubmit={handleSubmit}>
<ProgressBar currentStep={0} />
......@@ -132,6 +132,7 @@ const CorrespondentForm = ({ handleClose }) => (
<ValidatedField
label="Email"
name="submissionMeta.correspondent.email"
type="email"
/>
</Box>
<Box width={1 / 2}>
......
import React from 'react'
import { Formik } from 'formik'
import { withRouter } from 'react-router-dom'
import omitDeep from 'omit-deep-lodash'
import AuthorDetails from './AuthorDetails'
import WithCurrentSubmission from './WithCurrentSubmission'
......@@ -8,19 +9,18 @@ import { schema } from './AuthorDetailsSchema'
const AuthorDetailsPage = ({ history }) => (
<WithCurrentSubmission>
{(updateSubmission, { loading, error, data }, initialValues) => (
{(updateSubmission, initialValues) => (
<Formik
component={AuthorDetails}
initialValues={initialValues}
onSubmit={(values, { setSubmitting }) => {
console.log(
'>>>>> app/components/submission/AuthorDetailsPage.js:16\n',
'values:',
values,
)
return updateSubmission()
onSubmit={(values, { setSubmitting, setErrors }) => {
const data = omitDeep(values, '__typename')
return updateSubmission({ variables: { data } })
.then(() => setSubmitting(false))
.then(() => history.push('/'))
.then(() => history.push('/submit/upload'))
.catch(errors => {
setErrors(errors)
})
}}
validationSchema={schema}
/>
......
......@@ -11,6 +11,13 @@ const email = () =>
const institution = () => yup.string().required('Institute is required')
const correspondent = () =>
yup.object().shape({
firstName: firstName(),
lastName: lastName(),
email: email(),
})
const schema = yup.object().shape({
submissionMeta: yup.object().shape({
displayCorrespondent: yup.boolean(),
......@@ -20,10 +27,9 @@ const schema = yup.object().shape({
email: email(),
institution: institution(),
}),
correspondent: yup.object().shape({
firstName: firstName(),
lastName: lastName(),
email: email(),
correspondent: yup.object().when('displayCorrespondent', {
is: true,
then: correspondent(),
}),
}),
})
......
......@@ -120,8 +120,8 @@ class WithCurrentSubmission extends React.Component {
return (
<Mutation mutation={UPDATE_SUBMISSION}>
{(updateSubmission, updateResult) =>
this.props.children(updateSubmission, updateResult, initialValues)
{updateSubmission =>
this.props.children(updateSubmission, initialValues)
}
</Mutation>
)
......
......@@ -79,6 +79,7 @@
"history": "^4.7.2",
"joi": "^10.0.6",
"lodash": "^4.17.5",
"omit-deep-lodash": "^1.0.0",
"prop-types": "^15.5.10",
"pubsweet-client": "^2.4.0",
"pubsweet-server": "^6.0.0",
......
......@@ -6377,6 +6377,10 @@ lodash@4.17.5, "lodash@4.6.1 || ^4.16.1", lodash@^4, lodash@^4.0.0, lodash@^4.13
version "4.17.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
lodash@^4.11.1:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
log-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
......@@ -7197,6 +7201,12 @@ obuf@^1.0.0, obuf@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
omit-deep-lodash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/omit-deep-lodash/-/omit-deep-lodash-1.0.0.tgz#14406825e3a1ac9d232ee3f76fe424b640972884"
dependencies:
lodash "^4.11.1"
on-finished@^2.3.0, on-finished@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"
......
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