diff --git a/packages/component-dashboard/src/components/Dashboard.js b/packages/component-dashboard/src/components/Dashboard.js index 4cb225f0c1fabaccf9e0923957ef590f51730c7a..9805128060c9f8623199a5291014d75f101eeef5 100644 --- a/packages/component-dashboard/src/components/Dashboard.js +++ b/packages/component-dashboard/src/components/Dashboard.js @@ -18,6 +18,7 @@ const Dashboard = ({ deleteProject, reviewerResponse, uploadManuscript, + createDraftSubmission, }) => ( <div className={classes.root}> <div className={classes.upload}> @@ -27,6 +28,11 @@ const Dashboard = ({ /> </div> + <div> + Create new Submission + <button onClick={createDraftSubmission}>CREATE</button> + </div> + {!dashboard.owner.length && !dashboard.reviewer.length && !dashboard.editor.length && ( diff --git a/packages/component-dashboard/src/components/DashboardPage.js b/packages/component-dashboard/src/components/DashboardPage.js index e8efaac3c80fbda1ddd7a9bd0a646e89b57f4505..452238f0455cc679466db76f7a5b500ccdb4a610 100644 --- a/packages/component-dashboard/src/components/DashboardPage.js +++ b/packages/component-dashboard/src/components/DashboardPage.js @@ -4,7 +4,7 @@ import { withRouter } from 'react-router-dom' import { actions } from 'pubsweet-client' import { newestFirst, selectCurrentUser } from 'xpub-selectors' import { ConnectPage } from 'xpub-connect' -import { uploadManuscript } from '../redux/conversion' +import { uploadManuscript, createDraftSubmission } from '../redux/conversion' import Dashboard from './Dashboard' import AssignEditorContainer from './AssignEditorContainer' @@ -94,6 +94,7 @@ export default compose( dispatch(reviewerResponse(project, version, reviewer, status)), uploadManuscript: acceptedFiles => dispatch(uploadManuscript(acceptedFiles, history)), + createDraftSubmission: () => dispatch(createDraftSubmission(history)), }), ), withProps({ diff --git a/packages/component-dashboard/src/redux/conversion.js b/packages/component-dashboard/src/redux/conversion.js index 575cdbfb94d71a97e16c2e61aa03b068fba7bc7e..993e1026d334d67d1f1b8141f9d2d8ade947cc75 100644 --- a/packages/component-dashboard/src/redux/conversion.js +++ b/packages/component-dashboard/src/redux/conversion.js @@ -9,6 +9,10 @@ export const UPLOAD_MANUSCRIPT_REQUEST = 'UPLOAD_MANUSCRIPT_REQUEST' export const UPLOAD_MANUSCRIPT_SUCCESS = 'UPLOAD_MANUSCRIPT_SUCCESS' export const UPLOAD_MANUSCRIPT_FAILURE = 'UPLOAD_MANUSCRIPT_FAILURE' +// +export const CREATE_DRAFT_REQUEST = 'CREATE_DRAFT_REQUEST' +export const CREATE_DRAFT_SUCCESS = 'CREATE_DRAFT_SUCCESS' + /* actions */ export const uploadManuscriptRequest = () => ({ @@ -102,6 +106,45 @@ export const uploadManuscript = (acceptedFiles, history) => dispatch => { }) } +// faraday stuff +export const createDraftRequest = () => ({ + type: CREATE_DRAFT_REQUEST, +}) + +export const createDraftSuccess = draft => ({ + type: CREATE_DRAFT_SUCCESS, + draft, +}) + +export const createDraftSubmission = history => dispatch => + dispatch(actions.createCollection()).then(({ collection }) => { + if (!collection.id) { + throw new Error('Failed to create a project') + } + + // TODO: rethrow errors so they can be caught here + return dispatch( + actions.createFragment(collection, { + created: new Date(), // TODO: set on server + files: { + supplementary: [], + }, + fragmentType: 'version', + metadata: {}, + version: 1, + }), + ).then(({ fragment }) => { + dispatch(uploadManuscriptSuccess(collection, fragment)) + + const route = `/projects/${collection.id}/versions/${fragment.id}/submit` + + // redirect after a short delay + window.setTimeout(() => { + history.push(route) + }, 1000) + }) + }) + /* reducer */ const initialState = { @@ -131,7 +174,6 @@ export default (state = initialState, action) => { converting: false, error: action.error, } - default: return state } diff --git a/packages/component-wizard/src/components/Wizard.js b/packages/component-wizard/src/components/Wizard.js index a5655d471b3d148595b2ee8d5cd097895c5e897d..d6cb3b09b0ea3e58f2eaa24a05423a541606f19e 100644 --- a/packages/component-wizard/src/components/Wizard.js +++ b/packages/component-wizard/src/components/Wizard.js @@ -1,35 +1,43 @@ import React from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' +import { connect } from 'react-redux' +import { pick, debounce } from 'lodash' import { reduxForm } from 'redux-form' import { withJournal } from 'xpub-journal' +import { ConnectPage } from 'xpub-connect' import { ValidatedField, Button } from '@pubsweet/ui' +import { selectCollection, selectFragment } from 'xpub-selectors' import { compose, withHandlers, withState, getContext, withContext, + withProps, } from 'recompose' +import { actions } from 'pubsweet-client' import classes from './Wizard.local.scss' -import { Steps, SortableList } from './' +import { Steps } from './' const { Step } = Steps -const items = [ - { name: '1aurel', age: 2 }, - { name: '2costel' }, - { name: '3dorel' }, - { name: '4cocojambo' }, - { name: '5gicuta' }, -] - const validate = values => { const errors = {} return errors } +const onChange = (values, dispatch, { project, version }) => { + dispatch( + actions.updateFragment(project, { + id: version.id, + rev: version.rev, + ...values, + }), + ) +} + const WizardStep = ({ children: stepChildren, title, @@ -40,14 +48,17 @@ const WizardStep = ({ isFinal, isFirst, goBack, - ...rest }) => ( <div className={classnames(classes.step)}> - <form className={classnames(classes.form)} onSubmit={handleSubmit}> + <form + className={classnames(classes.form)} + name="metadata" + onSubmit={handleSubmit} + > <h3>{title}</h3> {stepChildren && stepChildren.map( - ({ fieldId, validate, renderComponent: Comp, ...rest }, index) => ( + ({ fieldId, validate, renderComponent: Comp, ...rest }) => ( <ValidatedField component={input => <Comp {...rest} {...input} />} key={fieldId} @@ -69,6 +80,18 @@ const WizardStep = ({ ) const FormStep = compose( + getContext({ + goBack: PropTypes.func, + isFinal: PropTypes.bool, + isFirst: PropTypes.bool, + project: PropTypes.object, + version: PropTypes.object, + wizard: PropTypes.object, + }), + withProps(({ version, wizard }) => ({ + initialValues: pick(version, wizard.formSectionKeys), + readonly: !!version.submitted, + })), reduxForm({ form: 'wizard', destroyOnUnmount: false, @@ -79,11 +102,7 @@ const FormStep = compose( nextStep() } }, - }), - getContext({ - goBack: PropTypes.func, - isFinal: PropTypes.bool, - isFirst: PropTypes.bool, + onChange: debounce(onChange, 1000, { maxWait: 5000 }), }), )(WizardStep) @@ -108,14 +127,21 @@ const Wizard = ({ ) export default compose( + ConnectPage(({ match }) => [ + actions.getCollection({ id: match.params.project }), + actions.getFragment( + { id: match.params.project }, + { id: match.params.version }, + ), + ]), + connect((state, { match }) => { + const project = selectCollection(state, match.params.project) + const version = selectFragment(state, match.params.version) + + return { project, version } + }), withJournal, withState('step', 'changeStep', 0), - withState('listItems', 'changeItems', items), - withHandlers({ - moveItem: ({ changeItems }) => (dragIndex, hoverIndex) => { - changeItems(prev => SortableList.moveItem(prev, dragIndex, hoverIndex)) - }, - }), withHandlers({ getSteps: ({ journal: { wizard: { steps } } }) => () => steps.map(w => w.label), @@ -130,11 +156,17 @@ export default compose( goBack: PropTypes.func, isFinal: PropTypes.bool, isFirst: PropTypes.bool, + project: PropTypes.object, + version: PropTypes.object, + wizard: PropTypes.object, }, - ({ history: { goBack }, step, journal: { wizard: { steps } } }) => ({ + ({ history: { goBack }, step, project, version, journal: { wizard } }) => ({ goBack, - isFinal: step === steps.length - 1, + isFinal: step === wizard.steps.length - 1, isFirst: step === 0, + project, + version, + wizard, }), ), )(Wizard) diff --git a/packages/component-wizard/src/redux/index.js b/packages/component-wizard/src/redux/index.js new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/packages/xpub-faraday/_build/config/client-config.json b/packages/xpub-faraday/_build/config/client-config.json index 5ff1882d200d00e927111b530cc2258d4af49b6d..f745f9ab7c33a0ede7be7b48fc3fb32c8eeb87cd 100644 --- a/packages/xpub-faraday/_build/config/client-config.json +++ b/packages/xpub-faraday/_build/config/client-config.json @@ -2,7 +2,7 @@ "pubsweet-client": { "API_ENDPOINT": "/api", "login-redirect": "/", - "redux-log": false + "redux-log": true }, "authsome": { "mode": "/Users/alexandrumunt/Projects/Hindawi/xpub/packages/xpub-faraday/config/authsome.js", diff --git a/packages/xpub-faraday/api/db/development/CURRENT b/packages/xpub-faraday/api/db/development/CURRENT index b0fe36ef847afeb6c7a516529b07bfce002ecb5e..68076bd4518ce7dfba7ba11b9666806278e50b3f 100644 --- a/packages/xpub-faraday/api/db/development/CURRENT +++ b/packages/xpub-faraday/api/db/development/CURRENT @@ -1 +1 @@ -MANIFEST-000169 +MANIFEST-000215 diff --git a/packages/xpub-faraday/api/db/development/LOG b/packages/xpub-faraday/api/db/development/LOG index d05f2fd716af2824469d932e0fcdb4fcb65c5c0c..a8934606c57d4bc747424c0f3d81696f13e42f32 100644 --- a/packages/xpub-faraday/api/db/development/LOG +++ b/packages/xpub-faraday/api/db/development/LOG @@ -1,5 +1,5 @@ -2018/01/15-11:43:30.224354 70000fc12000 Recovering log #167 -2018/01/15-11:43:30.225277 70000fc12000 Level-0 table #170: started -2018/01/15-11:43:30.225698 70000fc12000 Level-0 table #170: 237 bytes OK -2018/01/15-11:43:30.226457 70000fc12000 Delete type=0 #167 -2018/01/15-11:43:30.226694 70000fc12000 Delete type=3 #165 +2018/01/16-10:07:46.038149 700008211000 Recovering log #214 +2018/01/16-10:07:46.039162 700008211000 Level-0 table #216: started +2018/01/16-10:07:46.039723 700008211000 Level-0 table #216: 1034 bytes OK +2018/01/16-10:07:46.040468 700008211000 Delete type=0 #214 +2018/01/16-10:07:46.040619 700008211000 Delete type=3 #212 diff --git a/packages/xpub-faraday/api/db/development/LOG.old b/packages/xpub-faraday/api/db/development/LOG.old index 22d3e70056b18214a6ea787afcac860833a26a09..23b19c244b724b891bddd7131d5d7f8493b29c4b 100644 --- a/packages/xpub-faraday/api/db/development/LOG.old +++ b/packages/xpub-faraday/api/db/development/LOG.old @@ -1,14 +1,5 @@ -2018/01/15-11:15:26.115293 700008d13000 Recovering log #164 -2018/01/15-11:15:26.116155 700008d13000 Level-0 table #166: started -2018/01/15-11:15:26.116639 700008d13000 Level-0 table #166: 237 bytes OK -2018/01/15-11:15:26.117729 700008d13000 Delete type=0 #164 -2018/01/15-11:15:26.117926 700008d13000 Delete type=3 #162 -2018/01/15-11:15:26.118145 700009599000 Compacting 4@0 + 1@1 files -2018/01/15-11:15:26.119425 700009599000 Generated table #168@0: 11 keys, 1463 bytes -2018/01/15-11:15:26.119451 700009599000 Compacted 4@0 + 1@1 files => 1463 bytes -2018/01/15-11:15:26.119586 700009599000 compacted to: files[ 0 1 0 0 0 0 0 ] -2018/01/15-11:15:26.119707 700009599000 Delete type=2 #160 -2018/01/15-11:15:26.119877 700009599000 Delete type=2 #163 -2018/01/15-11:15:26.120014 700009599000 Delete type=2 #166 -2018/01/15-11:15:26.120143 700009599000 Delete type=2 #155 -2018/01/15-11:15:26.120392 700009599000 Delete type=2 #157 +2018/01/15-17:26:32.121790 7000085c8000 Recovering log #211 +2018/01/15-17:26:32.122398 7000085c8000 Level-0 table #213: started +2018/01/15-17:26:32.123638 7000085c8000 Level-0 table #213: 237 bytes OK +2018/01/15-17:26:32.124506 7000085c8000 Delete type=0 #211 +2018/01/15-17:26:32.124653 7000085c8000 Delete type=3 #210 diff --git a/packages/xpub-faraday/app/config/journal/metadata.js b/packages/xpub-faraday/app/config/journal/metadata.js index 7d662e97b2b267abc000756cf3b2056e80d1f562..422009e4150d333be600272d9bb0ba104c9d4f38 100644 --- a/packages/xpub-faraday/app/config/journal/metadata.js +++ b/packages/xpub-faraday/app/config/journal/metadata.js @@ -3,3 +3,8 @@ export default { name: 'Hindawi Faraday', logo: '/assets/hindawi-logo.png', } + +export const journal = { + label: 'Hindawi Faraday', + value: 'hindawi-faraday', +} diff --git a/packages/xpub-faraday/app/config/journal/submit-wizard.js b/packages/xpub-faraday/app/config/journal/submit-wizard.js index ec2b0ff861746d5e2b00cf70eb6d6db763cefb24..0c0f29a29829d5d339498e21e3d08908ed1f5a52 100644 --- a/packages/xpub-faraday/app/config/journal/submit-wizard.js +++ b/packages/xpub-faraday/app/config/journal/submit-wizard.js @@ -10,7 +10,7 @@ import { import uploadFile from 'xpub-upload' import { required, minChars } from 'xpub-validators' -import { articleSections, articleTypes, declarations } from './' +import { articleSections, declarations } from './' const min3Chars = minChars(3) const yesNoWithLabel = ({ label, ...rest }) => ( @@ -20,18 +20,31 @@ const yesNoWithLabel = ({ label, ...rest }) => ( </div> ) +const journal = { + label: 'Hindawi Faraday', + value: 'hindawi-faraday', +} + export default { - showProgress: false, + showProgress: true, + formSectionKeys: [ + 'metadata', + 'declarations', + 'suggestions', + 'notes', + 'files', + ], steps: [ { label: 'Journal details', title: 'Jounal & Field Selection', children: [ { - fieldId: 'journal', + fieldId: 'metadata.journal', renderComponent: Menu, label: 'Journal', - options: articleTypes, + options: [journal], + value: journal.value, validate: [required], }, { @@ -48,7 +61,6 @@ export default { { label: 'Special 2.1', value: 'dd21' }, { label: 'Special 2.2', value: 'dd22' }, ], - validate: [required], }, ], }, @@ -62,6 +74,7 @@ export default { fieldId: 'declarations', renderComponent: CheckboxGroup, options: declarations.options, + validate: [required], }, ], }, diff --git a/packages/xpub-faraday/app/routes.js b/packages/xpub-faraday/app/routes.js index 20c408960cf84dfe4a5a58b95fc93f7e40de1cf0..dff1dde953e0d0b8c91dcdfe095bdc9c0681389f 100644 --- a/packages/xpub-faraday/app/routes.js +++ b/packages/xpub-faraday/app/routes.js @@ -22,7 +22,11 @@ const Routes = () => ( <Route component={LoginPage} exact path="/login" /> <PrivateRoute component={DashboardPage} exact path="/" /> <PrivateRoute component={LogoutPage} exact path="/logout" /> - <PrivateRoute component={Wizard} exact path="/wizard" /> + <PrivateRoute + component={Wizard} + exact + path="/projects/:project/versions/:version/submit" + /> </App> ) diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js index 36f785c3693194e7e9c1d5098f5f287f6f687de2..ac142cf190c5a2949aeb6142ab589fbb04fa27e3 100644 --- a/packages/xpub-faraday/config/default.js +++ b/packages/xpub-faraday/config/default.js @@ -24,7 +24,7 @@ module.exports = { 'pubsweet-client': { API_ENDPOINT: '/api', 'login-redirect': '/', - 'redux-log': false, + 'redux-log': true, theme: process.env.PUBSWEET_THEME, }, 'mail-transport': { diff --git a/packages/xpub-faraday/config/validations.js b/packages/xpub-faraday/config/validations.js index db61056394a3e2536b38e5dad8a74d88099348cb..fad768ca3b83fd9adad1769340742614b6de26a3 100644 --- a/packages/xpub-faraday/config/validations.js +++ b/packages/xpub-faraday/config/validations.js @@ -17,6 +17,7 @@ module.exports = { submitted: Joi.date(), source: Joi.string(), // TODO: move to a file metadata: Joi.object({ + journal: Joi.string(), title: Joi.string(), abstract: Joi.string(), articleType: Joi.string(), @@ -24,7 +25,7 @@ module.exports = { authors: Joi.array(), keywords: Joi.array(), }), - declarations: Joi.object().unknown(), + declarations: Joi.array(), suggestions: Joi.object({ reviewers: Joi.object({ suggested: Joi.array().items(Joi.string()),