From 8ce1e5bd038e0f29ea37e1840e464fffd69f109e Mon Sep 17 00:00:00 2001
From: Alexandru Munteanu <alexandru.munteanu@thinslices.com>
Date: Fri, 12 Jan 2018 14:00:24 +0200
Subject: [PATCH] Use components from pubsweet-ui for wizard steps

---
 .../src/components/SortableList.js            |   1 -
 .../src/components/Steps.local.scss           |   8 +-
 .../component-wizard/src/components/Wizard.js | 147 ++++++++----------
 .../_build/config/client-config.json          |   2 +-
 .../CURRENT                                   |   2 +-
 .../LOG                                       |  10 +-
 .../LOG.old                                   |   6 +-
 .../MANIFEST-000004                           | Bin 127 -> 0 bytes
 .../xpub-faraday/api/db/development/CURRENT   |   2 +-
 packages/xpub-faraday/api/db/development/LOG  |  10 +-
 .../xpub-faraday/api/db/development/LOG.old   |  19 ++-
 .../app/config/journal/declarations.js        |  30 ++++
 .../app/config/journal/submit-wizard.js       | 105 +++++--------
 packages/xpub-faraday/config/default.js       |   2 +-
 14 files changed, 174 insertions(+), 170 deletions(-)
 delete mode 100644 packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/MANIFEST-000004

diff --git a/packages/component-wizard/src/components/SortableList.js b/packages/component-wizard/src/components/SortableList.js
index 9004e4945..1273b9e12 100644
--- a/packages/component-wizard/src/components/SortableList.js
+++ b/packages/component-wizard/src/components/SortableList.js
@@ -31,7 +31,6 @@ const itemTarget = {
     if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
       return
     }
-
     moveItem(dragIndex, hoverIndex)
     monitor.getItem().index = hoverIndex
   },
diff --git a/packages/component-wizard/src/components/Steps.local.scss b/packages/component-wizard/src/components/Steps.local.scss
index 0977a8f01..b02d38008 100644
--- a/packages/component-wizard/src/components/Steps.local.scss
+++ b/packages/component-wizard/src/components/Steps.local.scss
@@ -8,14 +8,14 @@
 }
 
 .separator {
-  background-color: #555;
+  background-color: #000;
   flex: 1;
   height: 2px;
 }
 
 .step {
   align-items: center;
-  border: 2px solid #555;
+  border: 2px solid #000;
   border-radius: 50%;
   display: flex;
   height: 16px;
@@ -25,7 +25,7 @@
 }
 
 .bullet {
-  background-color: #555;
+  background-color: #000;
   border-radius: 50%;
   height: 10px;
   width: 10px;
@@ -42,7 +42,7 @@
 
 .success {
   align-items: center;
-  background-color: #555;
+  background-color: #000;
   border-radius: 50%;
   color: #fff;
   display: flex;
diff --git a/packages/component-wizard/src/components/Wizard.js b/packages/component-wizard/src/components/Wizard.js
index b25bc55df..b14fbc60a 100644
--- a/packages/component-wizard/src/components/Wizard.js
+++ b/packages/component-wizard/src/components/Wizard.js
@@ -1,9 +1,10 @@
 import React from 'react'
 import classnames from 'classnames'
 import { withJournal } from 'xpub-journal'
-import { compose, withHandlers, withState } from 'recompose'
-import { TextField, YesOrNo } from '@pubsweet/ui'
 import { AbstractEditor } from 'xpub-edit'
+import { reduxForm, Field } from 'redux-form'
+import { TextField, YesOrNo, Menu, Checkbox } from '@pubsweet/ui'
+import { compose, withHandlers, withState } from 'recompose'
 
 import classes from './Wizard.local.scss'
 import { Dropdown, Steps, SortableList, ButtonGroup } from './'
@@ -18,46 +19,76 @@ const items = [
   { name: '5gicuta' },
 ]
 
+const renderField = ({ renderComponent, input, ...rest }) => {
+  console.log('Render field', input, rest)
+  return React.createElement(renderComponent, { ...rest, ...input })
+}
+
+const WizardStep = ({
+  children: stepChildren,
+  title,
+  buttons,
+  nextStep,
+  prevStep,
+  onSubmit,
+  ...rest
+}) => (
+  <div className={classnames(classes.step)}>
+    <form onSubmit={onSubmit}>
+      <h3>{title}</h3>
+      {stepChildren &&
+        stepChildren.map((child, index) => (
+          <Field
+            component={renderField}
+            key={child.fieldId}
+            name={child.fieldId}
+            {...child}
+          />
+        ))}
+    </form>
+    <ButtonGroup buttons={buttons} onBack={prevStep} onNext={nextStep} />
+  </div>
+)
+
+const FormStep = compose(
+  reduxForm({
+    form: 'wizard',
+    onSubmit: () => console.log('am dat surmit'),
+    destroyOnUnmount: false,
+    forceUnregisterOnUnmount: true,
+  }),
+)(WizardStep)
+
 const Wizard = ({
   journal: { wizard },
   getSteps,
   step,
-  incrementStep,
-  decrementStep,
-  moveItem,
+  nextStep,
+  prevStep,
   listItems,
-  renderStep,
   renderChild,
-  disabled,
-  toggleBtn,
-}) => {
-  const { title, children: stepChildren, buttons: stepButtons } = wizard[step]
-  return (
-    <div className={classnames(classes.container)}>
-      <Steps currentStep={step}>
-        {getSteps().map((step, index) => (
-          <Step index={index} key={step} title={step} />
-        ))}
-      </Steps>
-      <button onClick={toggleBtn}>Toggle</button>
-      <div className={classnames(classes.step)}>
-        <h3>{title}</h3>
-        {stepChildren && stepChildren.map((sc, index) => renderChild(sc))}
-        <ButtonGroup
-          buttons={stepButtons}
-          disabled={disabled}
-          onBack={decrementStep}
-          onNext={incrementStep}
-        />
-      </div>
-    </div>
-  )
-}
+  handleSubmit,
+  ...rest
+}) => (
+  <div className={classnames(classes.container)}>
+    <Steps currentStep={step}>
+      {getSteps().map((step, index) => (
+        <Step index={index} key={step} title={step} />
+      ))}
+    </Steps>
+    <FormStep
+      {...wizard[step]}
+      nextStep={nextStep}
+      onSubmit={handleSubmit}
+      prevStep={prevStep}
+      renderChild={renderChild}
+    />
+  </div>
+)
 
 export default compose(
   withJournal,
   withState('step', 'changeStep', 0),
-  withState('disabled', 'changeBtn', true),
   withState('listItems', 'changeItems', items),
   withHandlers({
     moveItem: ({ changeItems }) => (dragIndex, hoverIndex) => {
@@ -66,57 +97,9 @@ export default compose(
   }),
   withHandlers({
     getSteps: ({ journal: { wizard } }) => () => wizard.map(w => w.label),
-    toggleBtn: ({ changeBtn }) => () => changeBtn(v => !v),
-    incrementStep: ({ changeStep, journal: { wizard } }) => () =>
+    nextStep: ({ changeStep, journal: { wizard } }) => () =>
       changeStep(step => (step === wizard.length ? step : step + 1)),
-    decrementStep: ({ changeStep }) => () =>
+    prevStep: ({ changeStep }) => () =>
       changeStep(step => (step <= 0 ? step : step - 1)),
-    renderChild: ({ listItems, moveItem }) => data => {
-      switch (data.type) {
-        case 'dropdown':
-          return (
-            <Dropdown
-              key={data.label}
-              label={data.label}
-              options={data.values}
-            />
-          )
-        case 'checkbox':
-          return (
-            <div key={data.label}>
-              <input type="checkbox" />
-              <label>{data.label}</label>
-            </div>
-          )
-        case 'text':
-          return <TextField label={data.label} />
-        case 'abstract':
-          return (
-            <div>
-              <span>{data.label}</span>
-              <AbstractEditor />
-            </div>
-          )
-        case 'yesno':
-          return (
-            <div>
-              <span>{data.label}</span>
-              <YesOrNo name={data.label} />
-            </div>
-          )
-        case 'sortable-list':
-          return (
-            <SortableList
-              items={listItems}
-              listItem={({ name, isDragging }) => (
-                <div style={{ opacity: isDragging ? 0.5 : 1 }}>{name}</div>
-              )}
-              moveItem={moveItem}
-            />
-          )
-        default:
-          return <div>sorry</div>
-      }
-    },
   }),
 )(Wizard)
diff --git a/packages/xpub-faraday/_build/config/client-config.json b/packages/xpub-faraday/_build/config/client-config.json
index 5ff1882d2..f745f9ab7 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-mrview-fe0ff9878713e4fffce6b37f75b19960/CURRENT b/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/CURRENT
index cacca7574..875cf2335 100644
--- a/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/CURRENT
+++ b/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/CURRENT
@@ -1 +1 @@
-MANIFEST-000004
+MANIFEST-000007
diff --git a/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG b/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG
index 08df6d5d0..241afc923 100644
--- a/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG
+++ b/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG
@@ -1,5 +1,5 @@
-2018/01/09-16:57:47.142452 70000509e000 Recovering log #3
-2018/01/09-16:57:47.142855 70000509e000 Level-0 table #5: started
-2018/01/09-16:57:47.143583 70000509e000 Level-0 table #5: 339 bytes OK
-2018/01/09-16:57:47.144913 70000509e000 Delete type=0 #3
-2018/01/09-16:57:47.145131 70000509e000 Delete type=3 #2
+2018/01/12-10:37:25.695488 700004273000 Recovering log #6
+2018/01/12-10:37:25.697023 700004273000 Level-0 table #8: started
+2018/01/12-10:37:25.697468 700004273000 Level-0 table #8: 692 bytes OK
+2018/01/12-10:37:25.698638 700004273000 Delete type=0 #6
+2018/01/12-10:37:25.699530 700004273000 Delete type=3 #4
diff --git a/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG.old b/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG.old
index 6e96e3ba8..08df6d5d0 100644
--- a/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG.old
+++ b/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/LOG.old
@@ -1 +1,5 @@
-2018/01/09-16:57:26.656703 70000fc1f000 Delete type=3 #1
+2018/01/09-16:57:47.142452 70000509e000 Recovering log #3
+2018/01/09-16:57:47.142855 70000509e000 Level-0 table #5: started
+2018/01/09-16:57:47.143583 70000509e000 Level-0 table #5: 339 bytes OK
+2018/01/09-16:57:47.144913 70000509e000 Delete type=0 #3
+2018/01/09-16:57:47.145131 70000509e000 Delete type=3 #2
diff --git a/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/MANIFEST-000004 b/packages/xpub-faraday/api/db/development-mrview-fe0ff9878713e4fffce6b37f75b19960/MANIFEST-000004
deleted file mode 100644
index 4597cc10f5be066e7c0dbeeb78e75869d6b194ea..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 127
zcmWIhx#Ncn10$nUPHI_dPD+xVQ)NkNd1i5{bAE0?Vo_pAevx^x{M}FnMkY2+24;2^
z7Ip^K%S@_=_vhp%C+6rD0~Mqm-X9O<>E|RCmjtI4GO{p$f#Tu)xv3?IsEXoCOEXg#
H86heF%oizH

diff --git a/packages/xpub-faraday/api/db/development/CURRENT b/packages/xpub-faraday/api/db/development/CURRENT
index ffd4a0108..c16f179ff 100644
--- a/packages/xpub-faraday/api/db/development/CURRENT
+++ b/packages/xpub-faraday/api/db/development/CURRENT
@@ -1 +1 @@
-MANIFEST-000146
+MANIFEST-000156
diff --git a/packages/xpub-faraday/api/db/development/LOG b/packages/xpub-faraday/api/db/development/LOG
index 7594fbc0a..176c0c324 100644
--- a/packages/xpub-faraday/api/db/development/LOG
+++ b/packages/xpub-faraday/api/db/development/LOG
@@ -1,5 +1,5 @@
-2018/01/11-16:23:32.284236 700012094000 Recovering log #145
-2018/01/11-16:23:32.285724 700012094000 Level-0 table #147: started
-2018/01/11-16:23:32.286392 700012094000 Level-0 table #147: 237 bytes OK
-2018/01/11-16:23:32.287918 700012094000 Delete type=3 #143
-2018/01/11-16:23:32.288226 700012094000 Delete type=0 #145
+2018/01/12-13:50:08.231595 70000c302000 Recovering log #154
+2018/01/12-13:50:08.232541 70000c302000 Level-0 table #157: started
+2018/01/12-13:50:08.233098 70000c302000 Level-0 table #157: 237 bytes OK
+2018/01/12-13:50:08.233908 70000c302000 Delete type=3 #152
+2018/01/12-13:50:08.234059 70000c302000 Delete type=0 #154
diff --git a/packages/xpub-faraday/api/db/development/LOG.old b/packages/xpub-faraday/api/db/development/LOG.old
index 36a570ab0..afc31de34 100644
--- a/packages/xpub-faraday/api/db/development/LOG.old
+++ b/packages/xpub-faraday/api/db/development/LOG.old
@@ -1,5 +1,14 @@
-2018/01/11-16:21:42.691976 70000ed05000 Recovering log #141
-2018/01/11-16:21:42.692731 70000ed05000 Level-0 table #144: started
-2018/01/11-16:21:42.693203 70000ed05000 Level-0 table #144: 237 bytes OK
-2018/01/11-16:21:42.694106 70000ed05000 Delete type=3 #139
-2018/01/11-16:21:42.694255 70000ed05000 Delete type=0 #141
+2018/01/12-13:39:21.891350 70000d8d6000 Recovering log #151
+2018/01/12-13:39:21.892244 70000d8d6000 Level-0 table #153: started
+2018/01/12-13:39:21.892709 70000d8d6000 Level-0 table #153: 237 bytes OK
+2018/01/12-13:39:21.894383 70000d8d6000 Delete type=0 #151
+2018/01/12-13:39:21.894571 70000d8d6000 Delete type=3 #149
+2018/01/12-13:39:21.895409 70000d959000 Compacting 4@0 + 1@1 files
+2018/01/12-13:39:21.896309 70000d959000 Generated table #155@0: 11 keys, 1463 bytes
+2018/01/12-13:39:21.896335 70000d959000 Compacted 4@0 + 1@1 files => 1463 bytes
+2018/01/12-13:39:21.896502 70000d959000 compacted to: files[ 0 1 0 0 0 0 0 ]
+2018/01/12-13:39:21.896617 70000d959000 Delete type=2 #142
+2018/01/12-13:39:21.897278 70000d959000 Delete type=2 #147
+2018/01/12-13:39:21.898247 70000d959000 Delete type=2 #153
+2018/01/12-13:39:21.898532 70000d959000 Delete type=2 #150
+2018/01/12-13:39:21.898768 70000d959000 Delete type=2 #144
diff --git a/packages/xpub-faraday/app/config/journal/declarations.js b/packages/xpub-faraday/app/config/journal/declarations.js
index 012e4d46c..2f25fbee2 100644
--- a/packages/xpub-faraday/app/config/journal/declarations.js
+++ b/packages/xpub-faraday/app/config/journal/declarations.js
@@ -25,4 +25,34 @@ export default {
       legend: 'Pre-registered?',
     },
   ],
+  options: [
+    {
+      value: 'step2-1',
+      label: `I have the email addresses of all the co-authors of the manuscript.`,
+    },
+    {
+      value: 'step2-2',
+      label:
+        'I have the manuscript file in Microsoft Word or Adobe PDF format with the tables and figures integrated in the manuscript body.',
+    },
+    {
+      value: 'step2-3',
+      label:
+        'I have the electronic files of any supplementary materials (e.g., datasets, images, audio, video) that I want to submit with the manuscript.',
+    },
+    {
+      value: 'step2-4',
+      label:
+        'I am aware that accepted manuscripts are subject to Article Processing Charges.',
+    },
+    {
+      value: 'step2-5',
+      label: `I'm aware that an ORCID ID is required for the corresponding author before the article can be published (if accepted). The ORCID ID should added via your user account.`,
+    },
+    {
+      value: 'step2-6',
+      label:
+        'I am aware that if my submission is covered by an institutional membership, Hindawi will share details of the manuscript with the administrator of the membership.',
+    },
+  ],
 }
diff --git a/packages/xpub-faraday/app/config/journal/submit-wizard.js b/packages/xpub-faraday/app/config/journal/submit-wizard.js
index d917f739c..fa278669c 100644
--- a/packages/xpub-faraday/app/config/journal/submit-wizard.js
+++ b/packages/xpub-faraday/app/config/journal/submit-wizard.js
@@ -1,34 +1,32 @@
+import { AbstractEditor, TitleEditor } from 'xpub-edit'
+import { Menu, Checkbox, CheckboxGroup, YesOrNo, TextField } from '@pubsweet/ui'
+
+import { articleSections, articleTypes, declarations } from './'
+
 const wizard = [
   {
     label: 'Journal details',
     title: 'Jounal & Field Selection',
     children: [
       {
-        type: 'dropdown',
-        fullWidth: true,
-        label: 'Journal *',
-        values: [
-          { label: 'Dropdown 1.1', value: 'dd11' },
-          { label: 'Dropdown 1.2', value: 'dd12' },
-        ],
+        fieldId: 'journal',
+        renderComponent: Menu,
+        label: 'Journal',
+        options: articleTypes,
       },
       {
-        type: 'dropdown',
-        fullWidth: true,
+        fieldId: 'subject',
+        renderComponent: Menu,
         label: 'Subject area',
-        values: [
-          { label: 'Dropdown 2.1', value: 'dd21' },
-          { label: 'Dropdown 2.2', value: 'dd22' },
-        ],
+        options: articleSections,
       },
       {
-        type: 'dropdown',
-        fullWidth: true,
+        fieldId: 'specialIssue',
+        renderComponent: Menu,
         label: 'Special issue',
-        disabled: true,
-        values: [
-          { label: 'Dropdown 2.1', value: 'dd21' },
-          { label: 'Dropdown 2.2', value: 'dd22' },
+        options: [
+          { label: 'Special 2.1', value: 'dd21' },
+          { label: 'Special 2.2', value: 'dd22' },
         ],
       },
     ],
@@ -54,33 +52,9 @@ const wizard = [
       'Before moving forward make sure you have all the needed details prepared by reviewing and checking off the items on this list.',
     children: [
       {
-        type: 'checkbox',
-        label:
-          'I have the email addresses of all the co-authors of the manuscript.',
-      },
-      {
-        type: 'checkbox',
-        label:
-          'I have the manuscript file in Microsoft Word or Adobe PDF format with the tables and figures integrated in the manuscript body.',
-      },
-      {
-        type: 'checkbox',
-        label:
-          'I have the electronic files of any supplementary materials (e.g., datasets, images, audio, video) that I want to submit with the manuscript.',
-      },
-      {
-        type: 'checkbox',
-        label:
-          'I am aware that accepted manuscripts are subject to Article Processing Charges.',
-      },
-      {
-        type: 'checkbox',
-        label: `I'm aware that an ORCID ID is required for the corresponding author before the article can be published (if accepted). The ORCID ID should added via your user account.`,
-      },
-      {
-        type: 'checkbox',
-        label:
-          'I am aware that if my submission is covered by an institutional membership, Hindawi will share details of the manuscript with the administrator of the membership.',
+        fieldId: 'declarations',
+        renderComponent: CheckboxGroup,
+        options: declarations.options,
       },
     ],
     buttons: [
@@ -101,36 +75,39 @@ const wizard = [
       'Please provide the details of all the authors of this manuscript....',
     children: [
       {
-        type: 'text',
-        label: 'Manuscript title',
-        fullWidth: false,
+        fieldId: 'step3-1',
+        renderComponent: TitleEditor,
+        placeholder: 'Manuscript title',
+        title: 'Manuscript title',
       },
       {
-        type: 'dropdown',
+        fieldId: 'step3-2',
+        renderComponent: Menu,
         label: 'Manuscript type',
-        fullWidth: false,
-        values: [
+        options: [
           { label: 'Type 1', value: 'type1' },
           { label: 'Type 2', value: 'type2' },
         ],
       },
       {
-        type: 'abstract',
-        label: 'Abstract',
-        fullWidth: true,
-      },
-      {
-        key: 'authors',
-        type: 'sortable-list',
-        fullWidth: true,
-        label: 'Authors details',
+        fieldId: 'step3-3',
+        renderComponent: AbstractEditor,
+        title: 'Abstract',
+        placeholder: 'Write an abstract',
       },
+      // {
+      //   fieldId: 'authors',
+      //   renderComponent: 'sortable-list',
+      //   label: 'Authors details',
+      // },
       {
-        type: 'yesno',
+        fieldId: 'step3-4',
+        renderComponent: YesOrNo,
         label: 'Is there a potential conflict of interest?',
       },
       {
-        type: 'text',
+        fieldId: 'step3-5',
+        renderComponent: TextField,
         label: 'Conflict of interest details',
       },
     ],
@@ -145,6 +122,7 @@ const wizard = [
       },
     ],
   },
+  /*
   {
     label: 'Files upload',
     title: 'Manuscript Files Upload',
@@ -159,6 +137,7 @@ const wizard = [
       },
     ],
   },
+  */
 ]
 
 export default wizard
diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js
index 36f785c36..ac142cf19 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': {
-- 
GitLab