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

fix(author-list): fix isCorresponding checkbox

parent 5ee66935
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,6 @@ import { selectCollection, selectFragment } from 'xpub-selectors' ...@@ -9,8 +9,6 @@ import { selectCollection, selectFragment } from 'xpub-selectors'
import Submit from './Submit' import Submit from './Submit'
const onSubmit = (values, dispatch, { history, project, version }) => const onSubmit = (values, dispatch, { history, project, version }) =>
// console.log('submit', values)
dispatch( dispatch(
actions.updateFragment(project, { actions.updateFragment(project, {
id: version.id, id: version.id,
......
import React from 'react' import React, { Fragment } from 'react'
import { compose } from 'recompose' import { pick } from 'lodash'
import { Icon } from '@pubsweet/ui' import { Icon } from '@pubsweet/ui'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import styled from 'styled-components' import styled from 'styled-components'
import { reduxForm } from 'redux-form' import { compose, withHandlers, withProps } from 'recompose'
import { reduxForm, Field, change as changeForm } from 'redux-form'
import countries from './countries' import countries from './countries'
import { Spinner } from '../UIComponents' import { Spinner } from '../UIComponents'
...@@ -15,6 +16,10 @@ const emailRegex = new RegExp(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/) ...@@ -15,6 +16,10 @@ const emailRegex = new RegExp(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/)
const emailValidator = value => const emailValidator = value =>
emailRegex.test(value) ? undefined : 'Invalid email' emailRegex.test(value) ? undefined : 'Invalid email'
const renderCheckbox = ({ input }) => (
<input checked={input.value} type="checkbox" {...input} />
)
const AuthorEdit = ({ const AuthorEdit = ({
isFetching, isFetching,
setAuthorEdit, setAuthorEdit,
...@@ -23,19 +28,23 @@ const AuthorEdit = ({ ...@@ -23,19 +28,23 @@ const AuthorEdit = ({
index, index,
isSubmitting, isSubmitting,
isCorresponding, isCorresponding,
setAsCorresponding,
email, email,
changeCorresponding,
}) => ( }) => (
<Root> <Root>
<Header> <Header>
<TitleContainer> <TitleContainer>
<span>{parseAuthorType(isSubmitting, isCorresponding, index)}</span> <span>{parseAuthorType(isSubmitting, isCorresponding, index)}</span>
<input {!isSubmitting && (
checked={isCorresponding} <Fragment>
onChange={setAsCorresponding(email)} <Field
type="checkbox" component={renderCheckbox}
/> name="edit.isCorresponding"
<label>Corresponding</label> onChange={changeCorresponding(email)}
/>
<label>Corresponding</label>
</Fragment>
)}
</TitleContainer> </TitleContainer>
<ButtonsContainer> <ButtonsContainer>
...@@ -76,9 +85,34 @@ const AuthorEdit = ({ ...@@ -76,9 +85,34 @@ const AuthorEdit = ({
) )
export default compose( export default compose(
connect(state => ({ connect(
isFetching: getAuthorFetching(state), state => ({
isFetching: getAuthorFetching(state),
}),
{ changeForm },
),
withProps(props => ({
initialValues: {
edit: pick(props, [
'isCorresponding',
'firstName',
'lastName',
'middleName',
'email',
'affiliation',
'country',
]),
},
})), })),
withHandlers({
changeCorresponding: ({ changeForm, setAsCorresponding }) => email => (
evt,
newValue,
) => {
setAsCorresponding(email)()
changeForm('edit', 'edit.isCorresponding', newValue)
},
}),
reduxForm({ reduxForm({
form: 'edit', form: 'edit',
onSubmit: ( onSubmit: (
......
...@@ -124,10 +124,15 @@ export default compose( ...@@ -124,10 +124,15 @@ export default compose(
setFormAuthors(newAuthors) setFormAuthors(newAuthors)
}, },
setAsCorresponding: ({ authors, setFormAuthors }) => authorEmail => () => { setAsCorresponding: ({ authors, setFormAuthors }) => authorEmail => () => {
const newAuthors = authors.map(a => ({ const newAuthors = authors.map(
...a, a =>
isCorresponding: a.isSubmitting || a.email === authorEmail, a.email === authorEmail
})) ? {
...a,
isCorresponding: !a.isCorresponding,
}
: { ...a, isCorresponding: false },
)
setFormAuthors(newAuthors) setFormAuthors(newAuthors)
}, },
}), }),
......
...@@ -174,11 +174,11 @@ export default compose( ...@@ -174,11 +174,11 @@ export default compose(
if ( if (
allowedFileExtensions && allowedFileExtensions &&
allowedFileExtensions.includes(fileExtention) !allowedFileExtensions.includes(fileExtention)
) { ) {
addFile(file)
} else {
setError('Invalid file type.') setError('Invalid file type.')
} else {
addFile(file)
} }
}, },
}, },
......
...@@ -92,7 +92,7 @@ export default { ...@@ -92,7 +92,7 @@ export default {
fieldId: 'declarations', fieldId: 'declarations',
renderComponent: CheckboxGroup, renderComponent: CheckboxGroup,
options: declarations.options, options: declarations.options,
// validate: [required, declarationsMinSize], validate: [required, declarationsMinSize],
}, },
], ],
}, },
......
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