Skip to content
Snippets Groups Projects
Commit 50997b7d authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

Add option to have a confirmation modal before submitting

parent f7710835
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,14 @@ const onChange = ( ...@@ -29,7 +29,14 @@ const onChange = (
} }
} }
const submitManuscript = (values, dispatch, project, version, history) => { const submitManuscript = (
values,
dispatch,
project,
version,
history,
redirectPath = '/',
) => {
dispatch( dispatch(
actions.updateFragment(project, { actions.updateFragment(project, {
id: version.id, id: version.id,
...@@ -48,7 +55,7 @@ const submitManuscript = (values, dispatch, project, version, history) => { ...@@ -48,7 +55,7 @@ const submitManuscript = (values, dispatch, project, version, history) => {
), ),
) )
.then(() => { .then(() => {
history.push('/') history.push(redirectPath)
}) })
.catch(error => { .catch(error => {
if (error.validationErrors) { if (error.validationErrors) {
...@@ -60,12 +67,31 @@ const submitManuscript = (values, dispatch, project, version, history) => { ...@@ -60,12 +67,31 @@ const submitManuscript = (values, dispatch, project, version, history) => {
const onSubmit = ( const onSubmit = (
values, values,
dispatch, dispatch,
{ nextStep, isFinal, history, project, version, ...rest }, {
nextStep,
isFinal,
history,
project,
version,
confirmation,
wizard: { confirmationModal, submissionRedirect },
toggleConfirmation,
...rest
},
) => { ) => {
if (!isFinal) { if (!isFinal) {
nextStep() nextStep()
} else if (confirmationModal && !confirmation) {
toggleConfirmation()
} else { } else {
submitManuscript(values, dispatch, project, version, history) submitManuscript(
values,
dispatch,
project,
version,
history,
submissionRedirect,
)
} }
} }
...@@ -78,6 +104,8 @@ export default compose( ...@@ -78,6 +104,8 @@ export default compose(
version: PropTypes.object, version: PropTypes.object,
wizard: PropTypes.object, wizard: PropTypes.object,
dispatchFns: PropTypes.object, dispatchFns: PropTypes.object,
confirmation: PropTypes.bool,
toggleConfirmation: PropTypes.func,
}), }),
withProps(({ version, wizard }) => ({ withProps(({ version, wizard }) => ({
initialValues: pick(version, wizard.formSectionKeys), initialValues: pick(version, wizard.formSectionKeys),
......
...@@ -33,6 +33,7 @@ export default compose( ...@@ -33,6 +33,7 @@ export default compose(
}), }),
), ),
withState('step', 'changeStep', 0), withState('step', 'changeStep', 0),
withState('confirmation', 'setConfirmation', false),
withHandlers({ withHandlers({
getSteps: ({ journal: { wizard: { steps } } }) => () => getSteps: ({ journal: { wizard: { steps } } }) => () =>
steps.map(w => w.label), steps.map(w => w.label),
...@@ -41,6 +42,8 @@ export default compose( ...@@ -41,6 +42,8 @@ export default compose(
}, },
prevStep: ({ changeStep }) => () => prevStep: ({ changeStep }) => () =>
changeStep(step => (step <= 0 ? step : step - 1)), changeStep(step => (step <= 0 ? step : step - 1)),
toggleConfirmation: ({ setConfirmation }) => () =>
setConfirmation(confirmation => !confirmation),
}), }),
withContext( withContext(
{ {
...@@ -51,6 +54,8 @@ export default compose( ...@@ -51,6 +54,8 @@ export default compose(
version: PropTypes.object, version: PropTypes.object,
wizard: PropTypes.object, wizard: PropTypes.object,
dispatchFns: PropTypes.object, dispatchFns: PropTypes.object,
confirmation: PropTypes.bool,
toggleConfirmation: PropTypes.func,
}, },
({ ({
history, history,
...@@ -59,6 +64,8 @@ export default compose( ...@@ -59,6 +64,8 @@ export default compose(
version, version,
journal: { wizard }, journal: { wizard },
dispatchFns, dispatchFns,
confirmation,
toggleConfirmation,
}) => ({ }) => ({
history, history,
isFinal: step === wizard.steps.length - 1, isFinal: step === wizard.steps.length - 1,
...@@ -67,6 +74,8 @@ export default compose( ...@@ -67,6 +74,8 @@ export default compose(
version, version,
wizard, wizard,
dispatchFns, dispatchFns,
confirmation,
toggleConfirmation,
}), }),
), ),
)(Wizard) )(Wizard)
...@@ -19,6 +19,9 @@ export default ({ ...@@ -19,6 +19,9 @@ export default ({
formValues, formValues,
wizard, wizard,
dispatchFns, dispatchFns,
confirmation,
toggleConfirmation,
wizard: { confirmationModal: ConfirmationModal },
...rest ...rest
}) => ( }) => (
<div className={classnames(classes.step)}> <div className={classnames(classes.step)}>
...@@ -73,6 +76,11 @@ export default ({ ...@@ -73,6 +76,11 @@ export default ({
: `${wizard.nextText || 'Next'}`} : `${wizard.nextText || 'Next'}`}
</Button> </Button>
</div> </div>
{confirmation && (
<div className={classnames(classes.modal)}>
<ConfirmationModal toggleConfirming={toggleConfirmation} />
</div>
)}
</form> </form>
</div> </div>
) )
...@@ -30,3 +30,15 @@ ...@@ -30,3 +30,15 @@
margin: 15px 0; margin: 15px 0;
width: 400px; width: 400px;
} }
.modal {
align-items: center;
background: rgba(255, 255, 255, 0.95);
bottom: 0;
display: flex;
justify-content: center;
left: 0;
position: fixed;
right: 0;
top: 0;
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment