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'
import Submit from './Submit'
const onSubmit = (values, dispatch, { history, project, version }) =>
// console.log('submit', values)
dispatch(
actions.updateFragment(project, {
id: version.id,
......
import React from 'react'
import { compose } from 'recompose'
import React, { Fragment } from 'react'
import { pick } from 'lodash'
import { Icon } from '@pubsweet/ui'
import { connect } from 'react-redux'
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 { Spinner } from '../UIComponents'
......@@ -15,6 +16,10 @@ const emailRegex = new RegExp(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/)
const emailValidator = value =>
emailRegex.test(value) ? undefined : 'Invalid email'
const renderCheckbox = ({ input }) => (
<input checked={input.value} type="checkbox" {...input} />
)
const AuthorEdit = ({
isFetching,
setAuthorEdit,
......@@ -23,19 +28,23 @@ const AuthorEdit = ({
index,
isSubmitting,
isCorresponding,
setAsCorresponding,
email,
changeCorresponding,
}) => (
<Root>
<Header>
<TitleContainer>
<span>{parseAuthorType(isSubmitting, isCorresponding, index)}</span>
<input
checked={isCorresponding}
onChange={setAsCorresponding(email)}
type="checkbox"
/>
<label>Corresponding</label>
{!isSubmitting && (
<Fragment>
<Field
component={renderCheckbox}
name="edit.isCorresponding"
onChange={changeCorresponding(email)}
/>
<label>Corresponding</label>
</Fragment>
)}
</TitleContainer>
<ButtonsContainer>
......@@ -76,9 +85,34 @@ const AuthorEdit = ({
)
export default compose(
connect(state => ({
isFetching: getAuthorFetching(state),
connect(
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({
form: 'edit',
onSubmit: (
......
......@@ -124,10 +124,15 @@ export default compose(
setFormAuthors(newAuthors)
},
setAsCorresponding: ({ authors, setFormAuthors }) => authorEmail => () => {
const newAuthors = authors.map(a => ({
...a,
isCorresponding: a.isSubmitting || a.email === authorEmail,
}))
const newAuthors = authors.map(
a =>
a.email === authorEmail
? {
...a,
isCorresponding: !a.isCorresponding,
}
: { ...a, isCorresponding: false },
)
setFormAuthors(newAuthors)
},
}),
......
......@@ -174,11 +174,11 @@ export default compose(
if (
allowedFileExtensions &&
allowedFileExtensions.includes(fileExtention)
!allowedFileExtensions.includes(fileExtention)
) {
addFile(file)
} else {
setError('Invalid file type.')
} else {
addFile(file)
}
},
},
......
......@@ -92,7 +92,7 @@ export default {
fieldId: 'declarations',
renderComponent: CheckboxGroup,
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