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

feat(review): add confirmation modal

parent e7d98386
No related branches found
No related tags found
1 merge request!8Sprint #10
...@@ -3,7 +3,7 @@ import { connect } from 'react-redux' ...@@ -3,7 +3,7 @@ import { connect } from 'react-redux'
import { required } from 'xpub-validators' import { required } from 'xpub-validators'
import styled, { css } from 'styled-components' import styled, { css } from 'styled-components'
import { compose, withHandlers, withProps } from 'recompose' import { compose, withHandlers, withProps } from 'recompose'
import { th, Menu, ValidatedField, Icon, Button, Spinner } from '@pubsweet/ui' import { th, Menu, ValidatedField, Icon, Button } from '@pubsweet/ui'
import { import {
reduxForm, reduxForm,
isSubmitting, isSubmitting,
...@@ -15,6 +15,14 @@ import { ...@@ -15,6 +15,14 @@ import {
autosaveRequest, autosaveRequest,
autosaveSuccess, autosaveSuccess,
} from 'pubsweet-component-wizard/src/redux/autosave' } from 'pubsweet-component-wizard/src/redux/autosave'
import {
ConfirmationModal,
withModal2,
} from 'pubsweet-component-modal/src/components'
import {
selectFetching,
selectError,
} from 'pubsweet-components-faraday/src/redux/recommendations'
import { parseReviewResponseToForm, parseReviewRequest } from './utils' import { parseReviewResponseToForm, parseReviewRequest } from './utils'
...@@ -149,11 +157,7 @@ const ReviewerReportForm = ({ ...@@ -149,11 +157,7 @@ const ReviewerReportForm = ({
<Spacing /> <Spacing />
<Row> <Row>
{isSubmitting ? ( <ActionButton onClick={handleSubmit}> Submit report </ActionButton>
<Spinner size={4} />
) : (
<ActionButton onClick={handleSubmit}> Submit report </ActionButton>
)}
<AutosaveIndicator formName="reviewerReport" /> <AutosaveIndicator formName="reviewerReport" />
</Row> </Row>
</Root> </Root>
...@@ -162,6 +166,15 @@ const ReviewerReportForm = ({ ...@@ -162,6 +166,15 @@ const ReviewerReportForm = ({
// To be removed // To be removed
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
const ModalWrapper = compose(
connect(state => ({
fetching: selectFetching(state),
modalError: selectError(state),
})),
)(({ fetching, ...rest }) => (
<ConfirmationModal {...rest} isFetching={fetching} />
))
export default compose( export default compose(
connect( connect(
state => ({ state => ({
...@@ -173,6 +186,9 @@ export default compose( ...@@ -173,6 +186,9 @@ export default compose(
withProps(() => ({ withProps(() => ({
initialValues: parseReviewResponseToForm({}), initialValues: parseReviewResponseToForm({}),
})), })),
withModal2(props => ({
modalComponent: ModalWrapper,
})),
withHandlers({ withHandlers({
changeField: ({ changeForm }) => (field, value) => { changeField: ({ changeForm }) => (field, value) => {
changeForm('reviewerReport', field, value) changeForm('reviewerReport', field, value)
...@@ -186,12 +202,25 @@ export default compose( ...@@ -186,12 +202,25 @@ export default compose(
dispatch(autosaveRequest()) dispatch(autosaveRequest())
sleep(1000).then(() => dispatch(autosaveSuccess(new Date()))) sleep(1000).then(() => dispatch(autosaveSuccess(new Date())))
}, },
onSubmit: (values, dispatch, { isSubmitting }) => onSubmit: (values, dispatch, { isSubmitting, showModal, hideModal }) => {
sleep(1000).then(() => { showModal({
// TODO: link to backend title: 'Ready to Submit your Report?',
const review = parseReviewRequest(values) subtitle: 'Once submitted, the report can`t be modified',
window.alert(`You submitted:\n\n${JSON.stringify(review, null, 2)}`) confirmText: 'Submit report',
}), onConfirm: () => {
sleep(1000)
.then(hideModal)
.then(() => {
// TODO: link to backend
const review = parseReviewRequest(values)
window.alert(
`You submitted:\n\n${JSON.stringify(review, null, 2)}`,
)
})
},
onCancel: hideModal,
})
},
}), }),
)(ReviewerReportForm) )(ReviewerReportForm)
......
import { get } from 'lodash'
import { import {
get as apiGet, get as apiGet,
create, create,
...@@ -36,6 +37,12 @@ export const updateRecommendationSuccess = recommendation => ({ ...@@ -36,6 +37,12 @@ export const updateRecommendationSuccess = recommendation => ({
payload: { recommendation }, payload: { recommendation },
}) })
// Selectors
export const selectFetching = state =>
get(state, 'recommendations.fetching') || false
export const selectError = state => get(state, 'recommendations.error')
// Actions // Actions
// State // State
......
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