From 53e4e6734687ebf549228ca16de7997503f08dd7 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers <hamelers@ebi.ac.uk> Date: Fri, 20 Jul 2018 16:52:50 +0100 Subject: [PATCH] main page link works in banner (#77) end submission button works (fix: #62) --- app/components/CreateSetupPage.jsx | 81 +++++++++++++ app/components/Dashboard.jsx | 177 ++++++++++++----------------- app/components/DashboardPage.jsx | 37 ------ app/components/PubMedSearch.jsx | 8 +- app/routes.js | 4 +- 5 files changed, 162 insertions(+), 145 deletions(-) create mode 100644 app/components/CreateSetupPage.jsx diff --git a/app/components/CreateSetupPage.jsx b/app/components/CreateSetupPage.jsx new file mode 100644 index 000000000..6022cad1d --- /dev/null +++ b/app/components/CreateSetupPage.jsx @@ -0,0 +1,81 @@ +import React from 'react' +import { compose } from 'recompose' +import { connect } from 'react-redux' +import { withRouter } from 'react-router-dom' +import { actions } from 'pubsweet-client' +import { selectCurrentUser } from 'xpub-selectors' +import { ConnectPage } from 'xpub-connect' +import { H2 } from '@pubsweet/ui' +import { SplitPage, InfoPanel, StepPanel } from './ui/' +import CreateHeader from './CreateHeader' +import CreateInfo from './CreateInfo' +import PubMedSearch from './PubMedSearch' + +const createManuscript = (citationData, history) => dispatch => { + const { title, specialInstructions, ...other } = citationData + dispatch(actions.createCollection({ title })).then(({ collection }) => { + if (!collection.id) { + throw new Error('Failed to create a project') + } + // TODO: create teams? + // TODO: rethrow errors so they can be caught here + const data = { + created: new Date(), // TODO: set on server + fragmentType: 'version', + metadata: { + title, + ...other, + }, + version: 1, + } + if (specialInstructions) { + data.notes = { + specialInstructions, + } + } + return dispatch(actions.createFragment(collection, data)).then( + ({ fragment }) => { + const route = `/projects/${collection.id}/versions/${ + fragment.id + }/create` + history.push(route) + }, + ) + }) +} + +const CreateSetup = ({ createManuscript }) => ( + <SplitPage> + <StepPanel> + <div> + <CreateHeader currentStep={0} /> + <H2>Citation</H2> + <PubMedSearch citationData={createManuscript} /> + </div> + </StepPanel> + <InfoPanel> + <CreateInfo currentStep={0} /> + </InfoPanel> + </SplitPage> +) + +export default compose( + ConnectPage(() => [ + actions.getCollections(), + actions.getTeams(), + actions.getUsers(), + ]), + connect( + state => { + const { collections } = state + const { conversion } = state + const currentUser = selectCurrentUser(state) + return { collections, conversion, currentUser } + }, + (dispatch, { history }) => ({ + createManuscript: citationData => + dispatch(createManuscript(citationData, history)), + }), + ), + withRouter, +)(CreateSetup) diff --git a/app/components/Dashboard.jsx b/app/components/Dashboard.jsx index a9aebb2a3..5e175e339 100644 --- a/app/components/Dashboard.jsx +++ b/app/components/Dashboard.jsx @@ -1,13 +1,10 @@ import React from 'react' import { th } from '@pubsweet/ui-toolkit' -import { Button, H2 } from '@pubsweet/ui' +import { Button, H1, H2, Link } from '@pubsweet/ui' import styled from 'styled-components' import withVersion from 'pubsweet-component-xpub-dashboard/src/components/withVersion' -import { Page, SplitPage, InfoPanel, StepPanel } from './ui/' -import CreateHeader from './CreateHeader' -import CreateInfo from './CreateInfo' -import PubMedSearch from './PubMedSearch' +import { Page } from './ui/' import DashboardItem from './DashboardItem' const DashboardItemWithVersion = withVersion(DashboardItem) @@ -16,9 +13,6 @@ const UploadContainer = styled.div` display: flex; justify-content: center; ` -const BigLink = styled(Button)` - font-size: ${th('fontSizeHeading1')}; -` const Section = styled.div` margin: calc(${th('gridUnit')} * 3) 0; @@ -32,103 +26,82 @@ const DashboardItemList = styled.ul` padding: 0; border: ${th('borderWidth')} ${th('borderStyle')} ${th('colorBackgroundHue')}; ` -export default class DashSwitch extends React.Component { - constructor(props) { - super(props) - this.state = { - showButton: false, - } - } - render() { - const { - currentUser, - dashboard, - deleteProject, - createManuscript, - } = this.props - if (this.state.showButton) { - return ( - <SplitPage> - <StepPanel> - <div> - <CreateHeader currentStep={0} /> - <H2>Citation</H2> - <PubMedSearch citationData={createManuscript} /> - </div> - </StepPanel> - <InfoPanel> - <CreateInfo currentStep={0} /> - </InfoPanel> - </SplitPage> - ) - } - return ( - <Page> - <UploadContainer> - <BigLink onClick={() => this.setState({ showButton: true })} primary> +const Dashboard = ({ + currentUser, + dashboard, + deleteProject, + createManuscript, +}) => ( + <Page> + <UploadContainer> + <H1> + <Link to="/create"> + <Button primary style={{ fontSize: 'inherit' }}> Submit a new manuscript - </BigLink> + </Button> + </Link> + </H1> + </UploadContainer> + + {/* !dashboard.owner.length && + !dashboard.reviewer.length && + !dashboard.editor.length && ( + <UploadContainer> + Nothing to do at the moment. Please upload a document. </UploadContainer> + ) */} - {/* !dashboard.owner.length && - !dashboard.reviewer.length && - !dashboard.editor.length && ( - <UploadContainer> - Nothing to do at the moment. Please upload a document. - </UploadContainer> - ) */} + {!!dashboard.owner.length && ( + <Section> + <H2>My Submissions</H2> + <DashboardItemList> + {dashboard.owner.map(project => ( + <DashboardItemWithVersion + currentUser={currentUser} + deleteProject={() => + // eslint-disable-next-line no-alert + window.confirm( + 'Are you sure you want to delete this submission?', + ) && deleteProject(project) + } + key={project.id} + project={project} + /> + ))} + </DashboardItemList> + </Section> + )} - {!!dashboard.owner.length && ( - <Section> - <H2>My Submissions</H2> - <DashboardItemList> - {dashboard.owner.map(project => ( - <DashboardItemWithVersion - currentUser={currentUser} - deleteProject={() => - // eslint-disable-next-line no-alert - window.confirm( - 'Are you sure you want to delete this submission?', - ) && deleteProject(project) - } - key={project.id} - project={project} - /> - ))} - </DashboardItemList> - </Section> - )} + {!!dashboard.reviewer.length && ( + <Section> + <H2>To review</H2> + <DashboardItemList> + {dashboard.reviewer.map(project => ( + <DashboardItemWithVersion + currentUser={currentUser} + key={project.id} + project={project} + /> + ))} + </DashboardItemList> + </Section> + )} - {!!dashboard.reviewer.length && ( - <Section> - <H2>To review</H2> - <DashboardItemList> - {dashboard.reviewer.map(project => ( - <DashboardItemWithVersion - currentUser={currentUser} - key={project.id} - project={project} - /> - ))} - </DashboardItemList> - </Section> - )} + {!!dashboard.editor.length && ( + <Section> + <H2>My Manuscripts</H2> + <DashboardItemList> + {dashboard.editor.map(project => ( + <DashboardItemWithVersion + currentUser={currentUser} + key={project.id} + project={project} + /> + ))} + </DashboardItemList> + </Section> + )} + </Page> +) - {!!dashboard.editor.length && ( - <Section> - <H2>My Manuscripts</H2> - <DashboardItemList> - {dashboard.editor.map(project => ( - <DashboardItemWithVersion - currentUser={currentUser} - key={project.id} - project={project} - /> - ))} - </DashboardItemList> - </Section> - )} - </Page> - ) - } -} +export default Dashboard diff --git a/app/components/DashboardPage.jsx b/app/components/DashboardPage.jsx index e48fb826f..b908b7b22 100644 --- a/app/components/DashboardPage.jsx +++ b/app/components/DashboardPage.jsx @@ -18,39 +18,6 @@ const reviewerResponse = (project, version, reviewer, status) => dispatch => { ) } -const createManuscript = (citationData, history) => dispatch => { - const { title, specialInstructions, ...other } = citationData - dispatch(actions.createCollection({ title })).then(({ collection }) => { - if (!collection.id) { - throw new Error('Failed to create a project') - } - // TODO: create teams? - // TODO: rethrow errors so they can be caught here - const data = { - created: new Date(), // TODO: set on server - fragmentType: 'version', - metadata: { - title, - ...other, - }, - version: 1, - } - if (specialInstructions) { - data.notes = { - specialInstructions, - } - } - return dispatch(actions.createFragment(collection, data)).then( - ({ fragment }) => { - const route = `/projects/${collection.id}/versions/${ - fragment.id - }/create` - history.push(route) - }, - ) - }) -} - export default compose( ConnectPage(() => [ actions.getCollections(), @@ -129,10 +96,6 @@ export default compose( dispatch(actions.deleteCollection(collection)), reviewerResponse: (project, version, reviewer, status) => dispatch(reviewerResponse(project, version, reviewer, status)), - /* uploadManuscript: acceptedFiles => - dispatch(uploadManuscript(acceptedFiles, history)), */ - createManuscript: citationData => - dispatch(createManuscript(citationData, history)), }), ), withRouter, diff --git a/app/components/PubMedSearch.jsx b/app/components/PubMedSearch.jsx index 6d6aa6dba..76060be23 100644 --- a/app/components/PubMedSearch.jsx +++ b/app/components/PubMedSearch.jsx @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom' import { withRouter } from 'react-router-dom' import styled from 'styled-components' import { th } from '@pubsweet/ui-toolkit' -import { Button, Icon, H2 } from '@pubsweet/ui' +import { Button, Icon, H2, Link } from '@pubsweet/ui' import { A, B, @@ -187,9 +187,9 @@ class PubMedSearch extends React.Component { this.state.pmcid } for grant reporting purposes.`}</p> <Buttons> - <Button onClick={() => window.location.reload()} primary> - End Submission - </Button> + <Link to="/"> + <Button primary>End Submission</Button> + </Link> <Button onClick={() => this.setState({ diff --git a/app/routes.js b/app/routes.js index 54db9c1b1..35378b48c 100644 --- a/app/routes.js +++ b/app/routes.js @@ -20,9 +20,9 @@ import ReviewPage from 'pubsweet-component-xpub-review/src/components/ReviewPage import DecisionPage from 'pubsweet-component-xpub-review/src/components/DecisionPage' import UsersManager from 'pubsweet-component-users-manager/src/UsersManagerContainer' -import GrantSearch from './components/GrantSearch' import DashboardPage from './components/DashboardPage' import CreatePage from './components/CreatePage' +import CreateSetupPage from './components/CreateSetupPage' import SubmitPage from './components/SubmitPage' import App from './components/App' @@ -45,8 +45,8 @@ const Routes = () => ( <App> <Switch> {/* for testing purpose */} - <PrivateRoute component={GrantSearch} exact path="/grant-search" /> <PrivateRoute component={DashboardPage} exact path="/" /> + <PrivateRoute component={CreateSetupPage} exact path="/create" /> <PrivateRoute component={CreatePage} exact -- GitLab