Skip to content
Snippets Groups Projects
Commit 8f634d9a authored by Sebastian Mihalache's avatar Sebastian Mihalache :hammer_pick:
Browse files

Merge branch 'hin-982' into 'develop'

Hin 982

See merge request !68
parents c9a4bf06 92152072
No related branches found
No related tags found
2 merge requests!110Sprint 21 Features,!68Hin 982
Showing
with 2051 additions and 100 deletions
......@@ -4,7 +4,14 @@ import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { required } from 'xpub-validators'
import { reduxForm, Field } from 'redux-form'
import { H3, ValidatedField, TextField, Checkbox, Spinner } from '@pubsweet/ui'
import {
Menu,
H3,
ValidatedField,
TextField,
Checkbox,
Spinner,
} from '@pubsweet/ui'
import {
compose,
withState,
......@@ -13,6 +20,7 @@ import {
setDisplayName,
} from 'recompose'
import { withCountries } from 'pubsweet-component-faraday-ui'
import { Tag, Label, Row, Item, PersonInfo, IconButton, OpenModal } from './'
import { validators } from './helpers'
......@@ -119,6 +127,7 @@ const AuthorTitle = ({
// #region AuthorEdit
const AuthorEdit = ({
countries,
author,
editMode,
listIndex,
......@@ -169,7 +178,7 @@ const AuthorEdit = ({
validate={[required]}
/>
</Item>
<Item vertical>
<Item mr={1} vertical>
<Label required>Affiliation</Label>
<ValidatedField
component={TextField}
......@@ -177,12 +186,22 @@ const AuthorEdit = ({
validate={[required]}
/>
</Item>
<Item vertical>
<Label required>Country</Label>
<ValidatedField
component={input => (
<Menu {...input} options={countries} placeholder="Please select" />
)}
name="country"
/>
</Item>
</Row>
</AuthorContainer>
)
// #endregion
const EnhancedAuthorEdit = compose(
withCountries,
withProps(({ author }) => ({
initialValues: author,
})),
......
import React from 'react'
import PropTypes from 'prop-types'
import { withCountries } from 'pubsweet-component-faraday-ui'
import { Text, Row, Label, Item } from './'
......@@ -8,10 +9,12 @@ const defaultPerson = {
firstName: '',
lastName: '',
affiliation: '',
country: '',
}
const PersonInfo = ({
person: { email, firstName, lastName, affiliation } = defaultPerson,
person: { email, firstName, lastName, affiliation, country } = defaultPerson,
countryLabel,
}) => (
<Row>
<Item mr={1} vertical>
......@@ -26,10 +29,14 @@ const PersonInfo = ({
<Label>Last name</Label>
<Text>{lastName}</Text>
</Item>
<Item vertical>
<Item mr={1} vertical>
<Label>Affiliation</Label>
<Text>{affiliation}</Text>
</Item>
<Item vertical>
<Label>Country</Label>
<Text>{countryLabel(country)}</Text>
</Item>
</Row>
)
......@@ -39,7 +46,8 @@ PersonInfo.proTypes = {
firstName: PropTypes.string,
lastName: PropTypes.string,
affiliation: PropTypes.string,
country: PropTypes.string,
}),
}
export default PersonInfo
export default withCountries(PersonInfo)
/* eslint-disable handle-callback-err */
import React, { Fragment } from 'react'
import countrylist from 'country-list'
import { get } from 'lodash'
import styled from 'styled-components'
import { reduxForm } from 'redux-form'
......@@ -8,6 +7,7 @@ import { th } from '@pubsweet/ui-toolkit'
import { required as requiredValidator } from 'xpub-validators'
import { compose, withStateHandlers, withProps } from 'recompose'
import { H3, Spinner, ValidatedField, TextField, Menu } from '@pubsweet/ui'
import { withCountries } from 'pubsweet-component-faraday-ui'
import {
Row,
......@@ -21,16 +21,11 @@ import {
RowOverrideAlert,
} from './'
const countries = countrylist()
const countryList = countries
.getNames()
.map(c => ({ value: countries.getCode(c), label: c }))
const Profile = ({
title,
toggleEdit,
user: { affiliation, firstName, lastName, title: userTitle, country = '' },
countryLabel,
...rest
}) => (
<ShadowedBox position="relative" {...rest}>
......@@ -74,7 +69,7 @@ const Profile = ({
</Item>
<Item vertical>
<Label>Country</Label>
<Text secondary>{countries.getName(country)}</Text>
<Text secondary>{countryLabel(country)}</Text>
</Item>
</Row>
......@@ -128,79 +123,89 @@ const EditUserProfile = compose(
typeof onSave === 'function' && onSave(values, props)
},
}),
)(({ toggleEdit, title, handleSubmit, isFetching, fetchingError, ...rest }) => (
<ShadowedBox position="relative" {...rest}>
{isFetching ? (
<StyledSpinner>
<Spinner />
</StyledSpinner>
) : (
<EditModeIcons onSaveChanges={handleSubmit} toggleEdit={toggleEdit} />
)}
<Fragment>
<Row>
<Item>
<H3>Edit Account Details</H3>
</Item>
</Row>
<Row alignItems="baseline" mt={2}>
<Item mr={1} vertical>
<Label required>First Name</Label>
<ValidatedField
component={TextField}
name="firstName"
validate={[requiredValidator]}
/>
</Item>
<Item ml={1} vertical>
<Label required>Last Name</Label>
<ValidatedField
component={TextField}
name="lastName"
validate={[requiredValidator]}
/>
</Item>
</Row>
)(
({
toggleEdit,
title,
handleSubmit,
isFetching,
countries,
fetchingError,
...rest
}) => (
<ShadowedBox position="relative" {...rest}>
{isFetching ? (
<StyledSpinner>
<Spinner />
</StyledSpinner>
) : (
<EditModeIcons onSaveChanges={handleSubmit} toggleEdit={toggleEdit} />
)}
<Fragment>
<Row>
<Item>
<H3>Edit Account Details</H3>
</Item>
</Row>
<RowOverrideAlert alignItems="baseline" mt={2}>
<Item mr={1} vertical>
<Label required>Title</Label>
<ValidatedField
component={input => <Menu {...input} options={title} />}
name="title"
validate={[requiredValidator]}
/>
</Item>
<Item ml={1} vertical>
<Label required>Country</Label>
<ValidatedField
component={input => <Menu {...input} options={countryList} />}
name="country"
validate={[requiredValidator]}
/>
</Item>
</RowOverrideAlert>
<Row alignItems="baseline" mt={2}>
<Item mr={1} vertical>
<Label required>First Name</Label>
<ValidatedField
component={TextField}
name="firstName"
validate={[requiredValidator]}
/>
</Item>
<Item ml={1} vertical>
<Label required>Last Name</Label>
<ValidatedField
component={TextField}
name="lastName"
validate={[requiredValidator]}
/>
</Item>
</Row>
<Row alignItems="baseline" mt={2}>
<Item vertical>
<Label required>Affiliation</Label>
<ValidatedField
component={TextField}
name="affiliation"
validate={[requiredValidator]}
/>
</Item>
</Row>
<RowOverrideAlert alignItems="baseline" mt={2}>
<Item mr={1} vertical>
<Label required>Title</Label>
<ValidatedField
component={input => <Menu {...input} options={title} />}
name="title"
validate={[requiredValidator]}
/>
</Item>
<Item ml={1} vertical>
<Label required>Country</Label>
<ValidatedField
component={input => <Menu {...input} options={countries} />}
name="country"
validate={[requiredValidator]}
/>
</Item>
</RowOverrideAlert>
{fetchingError && (
<Row alignItems="center" mt={2}>
<Text error>{fetchingError}</Text>
<Row alignItems="baseline" mt={2}>
<Item vertical>
<Label required>Affiliation</Label>
<ValidatedField
component={TextField}
name="affiliation"
validate={[requiredValidator]}
/>
</Item>
</Row>
)}
</Fragment>
</ShadowedBox>
))
{fetchingError && (
<Row alignItems="center" mt={2}>
<Text error>{fetchingError}</Text>
</Row>
)}
</Fragment>
</ShadowedBox>
),
)
const UserProfile = ({
user,
......@@ -208,12 +213,21 @@ const UserProfile = ({
editMode,
toggleEdit,
journal: { title = [] },
countries,
countryLabel,
...rest
}) =>
!editMode ? (
<Profile title={title} toggleEdit={toggleEdit} user={user} {...rest} />
<Profile
countryLabel={countryLabel}
title={title}
toggleEdit={toggleEdit}
user={user}
{...rest}
/>
) : (
<EditUserProfile
countries={countries}
onSave={onSave}
title={title}
toggleEdit={toggleEdit}
......@@ -223,6 +237,7 @@ const UserProfile = ({
)
export default compose(
withCountries,
withStateHandlers(
{
editMode: false,
......
import { withProps } from 'recompose'
import countrylist from 'country-list'
const countryMapper = c => {
switch (c) {
case 'GB':
return 'UK'
case 'RS':
return 'SRB'
case 'ME':
return 'MNT'
case 'CG':
return 'CD'
default:
return c
}
}
const codeMapper = c => {
switch (c) {
case 'UK':
return 'GB'
case 'SRB':
return 'RS'
case 'MNT':
return 'ME'
case 'CD':
return 'CG'
default:
return c
}
}
const countries = countrylist()
const countryList = countries
.getNames()
.map(c => ({ value: countries.getCode(c), label: c }))
.map(c => ({ value: countryMapper(countries.getCode(c)), label: c }))
export default withProps(() => ({
countries: countryList,
countryLabel: code => countries.getName(codeMapper(code)),
}))
......@@ -56,6 +56,7 @@ class Fragment {
email: user.email,
title: user.title || '',
affiliation: user.affiliation || '',
country: user.country || '',
isSubmitting,
isCorresponding,
}
......
......@@ -9,17 +9,18 @@ class User {
async createUser({ role, body }) {
const { UserModel } = this
const { email, firstName, lastName, affiliation, title } = body
const { email, firstName, lastName, affiliation, title, country } = body
const username = email
const password = uuid.v4()
const userBody = {
username,
email,
title,
country,
username,
lastName,
password,
firstName,
lastName,
affiliation,
title,
isActive: true,
isConfirmed: false,
admin: role === 'admin',
......
......@@ -269,6 +269,7 @@ const sendAuthorsEmail = async ({
lastName: author.lastName,
affiliation: author.affiliation,
title: author.title,
country: author.country,
})
email.content.ctaText = 'CONFIRM ACCOUNT'
}
......
......@@ -21,7 +21,6 @@ const TR = ({
<td>{affiliation}</td>
</Row>
)
const Authors = ({ authors }) => (
<Table>
<thead>
......
......@@ -17,15 +17,29 @@ const authorKeys = [
'lastName',
'firstName',
'affiliation',
'country',
]
module.exports = models => async (req, res) => {
const { email, role, isSubmitting, isCorresponding } = req.body
const {
email,
role,
country,
lastName,
firstName,
affiliation,
isSubmitting,
isCorresponding,
} = req.body
if (
!services.checkForUndefinedParams(
email,
role,
country,
lastName,
firstName,
affiliation,
isSubmitting,
isCorresponding,
)
......
......@@ -22,6 +22,10 @@ const reqBody = {
role: 'author',
isSubmitting: true,
isCorresponding: false,
firstName: chance.first(),
lastName: chance.last(),
country: chance.country(),
affiliation: chance.company(),
}
describe('Post fragments users route handler', () => {
let testFixtures = {}
......
......@@ -32,7 +32,14 @@ export const isRevisionFlow = (state, collection, fragment = {}) =>
/* actions */
const addSubmittingAuthor = (user, collectionId, fragmentId) => {
const author = {
...pick(user, ['id', 'email', 'affiliation', 'firstName', 'lastName']),
...pick(user, [
'id',
'email',
'affiliation',
'firstName',
'lastName',
'country',
]),
isSubmitting: true,
isCorresponding: true,
}
......
......@@ -24,6 +24,7 @@ export default compose(
const lastName = params.get('lastName') || ''
const firstName = params.get('firstName') || ''
const affiliation = params.get('affiliation') || ''
const country = params.get('country') || ''
return {
initialValues: {
......@@ -33,6 +34,7 @@ export default compose(
lastName,
firstName,
affiliation,
country,
},
}
}),
......
......@@ -12,7 +12,6 @@ import {
Label,
ActionLink,
ItemOverrideAlert,
withCountries,
} from 'pubsweet-component-faraday-ui'
const AgreeCheckbox = ({ value, onChange }) => (
......@@ -74,13 +73,7 @@ const Step0 = ({
<ItemOverrideAlert ml={1} vertical>
<Label required>Country</Label>
<ValidatedField
component={input => (
<Menu
{...input}
options={countries}
placeholder="Please select"
/>
)}
component={TextField}
name="country"
validate={[requiredValidator]}
/>
......@@ -135,7 +128,6 @@ const Step0 = ({
)
export default compose(
withCountries,
reduxForm({
form: 'signUpInvitation',
destroyOnUnmount: false,
......
......@@ -148,6 +148,7 @@ export const parseUpdateUser = values => {
'lastName',
'affiliation',
'title',
'country',
'roles',
'editorInChief',
'handlingEditor',
......
source diff could not be displayed: it is too large. Options to address this: view the blob.
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