diff --git a/packages/component-invite/src/helpers/Collection.js b/packages/component-invite/src/helpers/Collection.js index 39ca1d2af015eeafb262b3a20f7b4391c62488fc..40542f54cfec481b0c32dfb862c8b45eec499d79 100644 --- a/packages/component-invite/src/helpers/Collection.js +++ b/packages/component-invite/src/helpers/Collection.js @@ -20,10 +20,10 @@ module.exports = { await collection.save() }, removeAssignedPeople: async (collection, email) => { - const assignedPeople = collection.assignedPeople.filter( - person => person.email !== email, - ) - collection.assignedPeople = assignedPeople + const assignedPeople = + collection.assignedPeople && + collection.assignedPeople.filter(person => person.email !== email) + collection.assignedPeople = assignedPeople || [] await collection.save() }, updateAssignedPeople: async (collection, email) => { diff --git a/packages/component-invite/src/helpers/Invitation.js b/packages/component-invite/src/helpers/Invitation.js index 31dd413ab5640b7e761f83c46718b08a93d53d8f..2337a9d1a1e135d6e215d84fa3aa6c72664bec39 100644 --- a/packages/component-invite/src/helpers/Invitation.js +++ b/packages/component-invite/src/helpers/Invitation.js @@ -1,10 +1,12 @@ const revokeInvitation = async (user, collectionId, type) => { - const filteredInvitations = user.invitations.filter( - invitation => - invitation.collectionId !== collectionId && invitation.type !== type, - ) + const filteredInvitations = + user.invitations && + user.invitations.filter( + invitation => + invitation.collectionId !== collectionId && invitation.type !== type, + ) - user.invitations = filteredInvitations + user.invitations = filteredInvitations || [] await user.save() } diff --git a/packages/component-invite/src/routes/deleteInvitation.js b/packages/component-invite/src/routes/deleteInvitation.js index b1f753296200196abf069ce14b9744d8a8adaac6..188158ba912769dad09d369a10fd3681be7a04ed 100644 --- a/packages/component-invite/src/routes/deleteInvitation.js +++ b/packages/component-invite/src/routes/deleteInvitation.js @@ -36,7 +36,6 @@ module.exports = models => async (req, res) => { role, models.Team, ) - if (team === undefined) { res.status(400).json({ error: `The requested collection does not have a ${role} Team`, diff --git a/packages/component-invite/src/routes/getCollectionUsers.js b/packages/component-invite/src/routes/getCollectionUsers.js index a6b3f5817aaf4a83f06a19bd95ca954d2cec7b0e..a68ffded06329f78a04cad18b5a86d3f0d5492a1 100644 --- a/packages/component-invite/src/routes/getCollectionUsers.js +++ b/packages/component-invite/src/routes/getCollectionUsers.js @@ -15,8 +15,8 @@ module.exports = models => async (req, res) => { res.status(400).json({ error: `Role ${role} is invalid` }) return } - const { collectionId } = req.params + console.log('req', role, collectionId) try { await models.Collection.find(collectionId) const members = await teamHelper.getTeamMembersByCollection( diff --git a/packages/components-faraday/src/components/AuthorList/Author.js b/packages/components-faraday/src/components/AuthorList/Author.js index 08d6c1eb749cf36eed05ea509bf81dbfeb3d7e14..a0092ad7d7644d0bca0f57fd25f9ef281161bf75 100644 --- a/packages/components-faraday/src/components/AuthorList/Author.js +++ b/packages/components-faraday/src/components/AuthorList/Author.js @@ -5,6 +5,7 @@ import styled from 'styled-components' import { Label } from './FormItems' export default ({ + id, firstName, middleName, lastName, @@ -29,7 +30,10 @@ export default ({ <Title>{parseAuthorType(isSubmitting, isCorresponding, index)}</Title> <ButtonContainer> {!isSubmitting && ( - <ClickableIcon onClick={removeAuthor(email)} title="Delete author"> + <ClickableIcon + onClick={removeAuthor(id, email)} + title="Delete author" + > <Icon size={3}>trash</Icon> </ClickableIcon> )} diff --git a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js index aef24acfa0d5657ceebb00eaf8bbc2f03b915895..5bb4d5917744c8cca6982a6a9dea6180f3da64e3 100644 --- a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js +++ b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js @@ -98,7 +98,6 @@ export default compose( { authors = [], addAuthor, setEditMode, setFormAuthors, reset, match }, ) => { const collectionId = get(match, 'params.project') - const fragmentId = get(match, 'params.version') const isFirstAuthor = authors.length === 0 addAuthor( { @@ -107,7 +106,6 @@ export default compose( isCorresponding: isFirstAuthor, }, collectionId, - fragmentId, ).then(author => { const newAuthors = [...authors, author] setEditMode(false)() diff --git a/packages/components-faraday/src/components/AuthorList/AuthorList.js b/packages/components-faraday/src/components/AuthorList/AuthorList.js index 7b6dd24e076b04c4b9b3c6e397d011c29721983a..c3505142b7c176178f07be5ab03e5c31f03b581e 100644 --- a/packages/components-faraday/src/components/AuthorList/AuthorList.js +++ b/packages/components-faraday/src/components/AuthorList/AuthorList.js @@ -15,7 +15,7 @@ import { import { change as changeForm } from 'redux-form' import { SortableList } from 'pubsweet-component-sortable-list/src/components' -import { addAuthor } from '../../redux/authors' +import { addAuthor, deleteAuthor, getAuthors } from '../../redux/authors' import Author from './Author' import countries from './countries' @@ -81,6 +81,7 @@ export default compose( { addAuthor, changeForm, + deleteAuthor, }, ), withState('authors', 'setAuthors', []), @@ -113,17 +114,22 @@ export default compose( if (isCorresponding) return `#${index + 1} Corresponding author` return `#${index + 1} Author` }, - moveAuthor: ({ authors, setAuthors, changeForm }) => ( + moveAuthor: ({ authors, setFormAuthors, changeForm }) => ( dragIndex, hoverIndex, ) => { const newAuthors = SortableList.moveItem(authors, dragIndex, hoverIndex) - setAuthors(newAuthors) - }, - removeAuthor: ({ authors, setFormAuthors }) => authorEmail => () => { - const newAuthors = authors.filter(a => a.email !== authorEmail) setFormAuthors(newAuthors) }, + removeAuthor: ({ authors, setFormAuthors, deleteAuthor, project }) => ( + id, + authorEmail, + ) => () => { + deleteAuthor(project.id, id).then(() => { + const newAuthors = authors.filter(a => a.id !== id) + setFormAuthors(newAuthors) + }) + }, setAsCorresponding: ({ authors, setFormAuthors }) => authorEmail => () => { const newAuthors = authors.map( a => @@ -139,8 +145,8 @@ export default compose( }), lifecycle({ componentDidMount() { - const { version, setAuthors } = this.props - setAuthors(version.authors) + const { setFormAuthors, project } = this.props + getAuthors(project.id).then(setFormAuthors) }, }), )(Authors) diff --git a/packages/components-faraday/src/redux/authors.js b/packages/components-faraday/src/redux/authors.js index a4219d6ae9872ef33d02364f2371bc01531bc1bd..10f6cc645ab334eb872dd282e5ea0f9e46235d08 100644 --- a/packages/components-faraday/src/redux/authors.js +++ b/packages/components-faraday/src/redux/authors.js @@ -1,4 +1,5 @@ import { get } from 'lodash' +import { create, get as apiGet, remove } from 'pubsweet-client/src/helpers/api' // constants const REQUEST = 'authors/REQUEST' @@ -19,8 +20,21 @@ export const authorSuccess = () => ({ type: SUCCESS, }) -export const addAuthor = (author, collectionId, fragmentId) => dispatch => - Promise.resolve(author) +export const addAuthor = (author, collectionId) => dispatch => { + dispatch(authorRequest()) + return create(`/users/invite/${collectionId}`, { + email: author.email, + role: 'author', + ...author, + }) +} + +export const deleteAuthor = (collectionId, userId) => dispatch => + remove(`/collections/${collectionId}/users/${userId}?role=author`) +// Promise.resolve(author) + +export const getAuthors = collectionId => + apiGet(`/collections/${collectionId}/users?role=author`) // selectors export const getFragmentAuthors = (state, fragmentId) => diff --git a/packages/xpub-faraday/app/config/journal/submit-wizard.js b/packages/xpub-faraday/app/config/journal/submit-wizard.js index ab50d4ab1c3067a9977febbb0ae7444d80880189..8654c6a2eb9b2222c089799fcc8501812d3b467e 100644 --- a/packages/xpub-faraday/app/config/journal/submit-wizard.js +++ b/packages/xpub-faraday/app/config/journal/submit-wizard.js @@ -51,13 +51,7 @@ const uploadFile = input => uploadFileFn(input) export default { showProgress: true, - formSectionKeys: [ - 'metadata', - 'declarations', - 'conflicts', - 'files', - 'authors', - ], + formSectionKeys: ['metadata', 'declarations', 'conflicts', 'files'], submissionRedirect: '/confirmation-page', dispatchFunctions: [uploadFile], steps: [