diff --git a/app/components/submission-wizard/ResolveDuplicates.jsx b/app/components/submission-wizard/ResolveDuplicates.jsx index f4b2ee281a3d3496469e3c5254ed46f839a59130..1ab79a1117a8de50d3b09e198db302590132554a 100644 --- a/app/components/submission-wizard/ResolveDuplicates.jsx +++ b/app/components/submission-wizard/ResolveDuplicates.jsx @@ -3,7 +3,7 @@ import { withRouter } from 'react-router' import { Mutation } from 'react-apollo' import styled from 'styled-components' import { th } from '@pubsweet/ui-toolkit' -import { H3, H4, Button, Action, Icon, Link } from '@pubsweet/ui' +import { H3, H4, Button, Icon, Link } from '@pubsweet/ui' import { B, Buttons, Close, CloseButton, Portal, Notification } from '../ui' import { States, timeSince } from '../dashboard' import Citation from './Citation' @@ -40,7 +40,7 @@ const Columns = styled.div` padding: calc(${th('gridUnit')} * 2); } ` -const Current = styled.div` +const Current = styled.div` background-color: ${th('colorBackground')}; ` const Dupes = styled.div` @@ -52,128 +52,167 @@ const FlexP = styled.div` align-items: center; justify-content: space-between; ` -const ResolveDuplicates = ({ close, current, duplicates }) => ( - <Mutation - mutation={REPLACE_MANUSCRIPT} - refetchQueries={result => { - if (result.data.replaceManuscript) { - return [ - { - query: CHECK_DUPES, - variables: { - id: current.id, - pmid: - current.meta.articleIds && - current.meta.articleIds.find(id => id.pubIdType === 'pmid') - ? current.meta.articleIds.find(id => id.pubIdType === 'pmid') - .id - : null, - title: current.meta.title, - }, - }, - ] - } - return [] - }} - > - {(replaceManuscript, { data }) => { - const replace = async (keepId, throwId) => { - const { data } = await replaceManuscript({ - variables: { keepId, throwId }, - }) - if (data.replaceManuscript && throwId === current.id) { - this.props.history.push('/') - } - } - console.log(duplicates) - return ( - <Portal transparent> - <Close> - <CloseButton onClick={close} /> - </Close> - <Columns> - <H3>This manuscript</H3> - <H3>Duplicate(s)</H3> - <p style={{ flex: '0 0 100%' }}> - <Notification type="error"> - Two articles cannot have the same PMID. - </Notification> - </p> - <Current> - <H4>{current.id}</H4> - <Citation journal={current.journal} metadata={current.meta} /> - <FlexP> - <span> - <B>Status:</B> {current.status} - </span> - <span> - <B>Last updated:</B> {timeSince(current.updated)} - </span> - </FlexP> - <p> - <B>Grants: </B> - {current.meta.fundingGroup && current.meta.fundingGroup.map((f, t) => ( - <span key={f.awardId}> - {`${f.fundingSource} ${f.awardId}`} - {t !== current.meta.fundingGroup.length - 1 && ', '} - </span> - ))} - </p> - <Button onClick={() => replace(current.id, duplicates[0].id)} primary> - Remove this & transfer grants - <Icon color="currentColor">arrow-right</Icon> - </Button> - </Current> - {duplicates.map((dupe, i) => ( - <React.Fragment> - <Dupes key={dupe.id}> - <H4>{dupe.id}</H4> - <Link - target="_blank" - to={`/submission/${dupe.id}/${ - States.admin[dupe.status].url - }`} - > - <Citation journal={dupe.journal} metadata={dupe.meta} /> - </Link> +class ResolveDuplicates extends React.Component { + state = { + error: false, + duplicates: this.props.duplicates, + } + unsetDupe = () => { + const { duplicates } = this.state + const { current } = this.props + if ( + current.meta.articleIds.find(id => id.pubIdType === 'pmid').id === + duplicates[0].meta.articleIds.find(id => id.pubIdType === 'pmid').id + ) { + this.setState({ error: true }) + } else { + duplicates.shift() + this.setState({ duplicates }) + } + } + render() { + console.log(this.unsetDupe) + const { close, current } = this.props + const { duplicates, error } = this.state + return ( + <Mutation + mutation={REPLACE_MANUSCRIPT} + refetchQueries={result => { + if (result.data.replaceManuscript) { + return [ + { + query: CHECK_DUPES, + variables: { + id: current.id, + pmid: + current.meta.articleIds && + current.meta.articleIds.find(id => id.pubIdType === 'pmid') + ? current.meta.articleIds.find( + id => id.pubIdType === 'pmid', + ).id + : null, + title: current.meta.title, + }, + }, + ] + } + return [] + }} + > + {(replaceManuscript, { data }) => { + const replace = async (keepId, throwId) => { + const { data } = await replaceManuscript({ + variables: { keepId, throwId }, + }) + if (data.replaceManuscript && throwId === current.id) { + this.props.history.push('/') + } + } + return ( + <Portal transparent> + <Close> + <CloseButton onClick={close} /> + </Close> + <Columns> + <H3>This manuscript</H3> + <H3>Duplicate(s)</H3> + {error && ( + <p style={{ flex: '0 0 100%' }}> + <Notification type="error"> + Two articles cannot have the same PMID. + </Notification> + </p> + )} + <Current> + <H4>{current.id}</H4> + <Citation journal={current.journal} metadata={current.meta} /> <FlexP> <span> - <B>Status:</B> {dupe.status} + <B>Status:</B> {current.status} </span> <span> - <B>Last updated:</B> {timeSince(dupe.updated)} + <B>Last updated:</B> {timeSince(current.updated)} </span> </FlexP> <p> <B>Grants: </B> - {dupe.meta.fundingGroup && dupe.meta.fundingGroup.map((f, t) => ( - <span key={f.awardId}> - {`${f.fundingSource} ${f.awardId}`} - {t !== dupe.meta.fundingGroup.length - 1 && ', '} - </span> - ))} + {current.meta.fundingGroup && + current.meta.fundingGroup.map((f, t) => ( + <span key={f.awardId}> + {`${f.fundingSource} ${f.awardId}`} + {t !== current.meta.fundingGroup.length - 1 && ', '} + </span> + ))} </p> - <Button onClick={() => replace(current.id, dupe.id)} primary> - <Icon color="currentColor">arrow-left</Icon> - Transfer grants & remove this + <Button + onClick={() => replace(current.id, duplicates[0].id)} + primary + > + Remove this & transfer grants + <Icon color="currentColor">arrow-right</Icon> </Button> - </Dupes> - {i === 0 && ( - <p style={{ flex: '0 0 100%', textAlign: 'center' }}> - <Button style={{ margin: '0 auto' }}>These two are not duplicates!</Button> - </p> - )} - {i !== duplicates.length - 1 && <br />} - </React.Fragment> - ))} - </Columns> - <Buttons> - <Button onClick={close}>Exit</Button> - </Buttons> - </Portal> - ) - }} - </Mutation> -) + </Current> + {duplicates.map((dupe, i) => ( + <React.Fragment key={dupe.id}> + <Dupes> + <H4>{dupe.id}</H4> + <Link + target="_blank" + to={`/submission/${dupe.id}/${ + States.admin[dupe.status].url + }`} + > + <Citation journal={dupe.journal} metadata={dupe.meta} /> + </Link> + <FlexP> + <span> + <B>Status:</B> {dupe.status} + </span> + <span> + <B>Last updated:</B> {timeSince(dupe.updated)} + </span> + </FlexP> + <p> + <B>Grants: </B> + {dupe.meta.fundingGroup && + dupe.meta.fundingGroup.map((f, t) => ( + <span key={f.awardId}> + {`${f.fundingSource} ${f.awardId}`} + {t !== dupe.meta.fundingGroup.length - 1 && ', '} + </span> + ))} + </p> + <Button + onClick={() => replace(current.id, dupe.id)} + primary + > + <Icon color="currentColor">arrow-left</Icon> + Transfer grants & remove this + </Button> + </Dupes> + {i === 0 && ( + <p style={{ flex: '0 0 100%', textAlign: 'center' }}> + <Button + onClick={() => this.unsetDupe()} + style={{ margin: '0 auto' }} + > + These two are not duplicates! + </Button> + </p> + )} + {i !== duplicates.length - 1 && <br />} + </React.Fragment> + ))} + </Columns> + <Buttons> + <Button onClick={close}>Exit</Button> + </Buttons> + </Portal> + ) + }} + </Mutation> + ) + } +} export default withRouter(ResolveDuplicates) diff --git a/app/components/submission-wizard/Submit.jsx b/app/components/submission-wizard/Submit.jsx index a1a6d3463f5af5f35b944044f269de5507fa6ffa..62190c3a40d79a8a81c82983a50935c44ed91627 100644 --- a/app/components/submission-wizard/Submit.jsx +++ b/app/components/submission-wizard/Submit.jsx @@ -367,7 +367,9 @@ class Submit extends React.Component { <div> <PanelHeader> <H2> - {status === 'submission-error' && 'Edit' || status === 'submitted' && 'Review' || 'Confirm'} + {(status === 'submission-error' && 'Edit') || + (status === 'submitted' && 'Review') || + 'Confirm'} {` input & approve`} </H2> </PanelHeader> diff --git a/app/components/submission-wizard/SubmitPage.jsx b/app/components/submission-wizard/SubmitPage.jsx index f26226bd43d1c6b750e689342b70492a7d261245..4e1e79244130f4e9700c66c8487498df70f4b492 100755 --- a/app/components/submission-wizard/SubmitPage.jsx +++ b/app/components/submission-wizard/SubmitPage.jsx @@ -27,7 +27,7 @@ const DupeCheckSubmitPage = ({ manuscript, ...props }) => { ) } const duplicates = - data.checkDuplicates.length > 0 && data.checkDuplicates || null + (data.checkDuplicates.length > 0 && data.checkDuplicates) || null return ( <SubmitWithHeader duplicates={duplicates} diff --git a/server/xpub-model/entities/manuscript/index.js b/server/xpub-model/entities/manuscript/index.js index 028945587f40066fb170362a560e142d9d28fe8d..115fb2dfcfaeed538e575281f115f076ad705135 100755 --- a/server/xpub-model/entities/manuscript/index.js +++ b/server/xpub-model/entities/manuscript/index.js @@ -6,9 +6,7 @@ const authorization = require('pubsweet-server/src/helpers/authorization') const logger = require('@pubsweet/logger') const EmailValidator = require('email-validator') const ManuscriptAccess = require('./data-access') -const FileAccess = require('../file/data-access') const NoteAccess = require('../note/data-access') -const ReviewAccess = require('../review/data-access') const UserAccess = require('../user/data-access') const Team = require('../team/data-access') const { dManuscriptUpdate, gManuscript } = require('./helpers/transform') @@ -164,7 +162,7 @@ const Manuscript = { } }, - create: async (userId, organizationId) => { + create: async (data, userId, organizationId) => { await authorization.can(userId, 'create', { id: null, type: 'Manuscript', @@ -181,7 +179,9 @@ const Manuscript = { status: config.manuscript.status.initial, }) savedMan = await manuscript.saveWithTrx(trx) - + const input = dManuscriptUpdate(data, userId) + lodash.assign(savedMan, input) + await savedMan.saveWithTrx(trx) const team = new Team({ manuscriptId: savedMan.id, userId,