Skip to content
Snippets Groups Projects
Commit b97544e4 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

fix multiple modals on the same page

parent c11433a4
No related branches found
No related tags found
No related merge requests found
export { default as withModal } from './withModal' export { default as withModal } from './withModal'
export { default as SuccessModal } from './SuccessModal' export { default as SuccessModal } from './SuccessModal'
export { default as ConfirmationModal } from './ConfirmationModal' export { default as ConfirmationModal } from './ConfirmationModal'
export { withModal2 } from './withModal'
import React from 'react' import React from 'react'
import { omit } from 'lodash' import { omit } from 'lodash'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { compose } from 'recompose'
import Modal from './Modal' import Modal from './Modal'
import { showModal, hideModal, setModalError } from '../redux/modal' import { showModal, hideModal, setModalError } from '../redux/modal'
...@@ -17,6 +18,47 @@ const mapDispatch = modalKey => (dispatch, propss) => ({ ...@@ -17,6 +18,47 @@ const mapDispatch = modalKey => (dispatch, propss) => ({
setModalError: errorMessage => dispatch(setModalError(errorMessage)), setModalError: errorMessage => dispatch(setModalError(errorMessage)),
}) })
const mapDispatch2 = (dispatch, props) => ({
hideModal: () => dispatch(hideModal()),
showModal: (modalProps = {}) =>
dispatch(showModal(props.modalKey, modalProps)),
setModalError: errorMessage => dispatch(setModalError(errorMessage)),
})
export const withModal2 = mapperFn => BaseComponent =>
compose(connect(mapState, mapDispatch2))(baseProps => {
const { modalComponent: Component, overlayColor } = mapperFn(baseProps)
const {
hideModal,
modalProps,
modalError,
modalsVisibility,
modalKey,
...rest
} = baseProps
return (
<React.Fragment>
{modalsVisibility[modalKey] && (
<Modal
{...modalProps}
component={Component}
hideModal={hideModal}
modalError={modalError}
overlayColor={overlayColor}
setModalError={setModalError}
showModal={showModal}
/>
)}
<BaseComponent
hideModal={hideModal}
setModalError={setModalError}
showModal={showModal}
{...rest}
/>
</React.Fragment>
)
})
const withModal = ({ const withModal = ({
modalKey, modalKey,
modalComponent: Component, modalComponent: Component,
......
...@@ -140,7 +140,10 @@ const DashboardCard = ({ ...@@ -140,7 +140,10 @@ const DashboardCard = ({
{renderHandlingEditorRow()} {renderHandlingEditorRow()}
</LeftDetails> </LeftDetails>
</Bottom> </Bottom>
<InviteReviewers project={project} /> <InviteReviewers
modalKey={`invite-reviewers-${project.id}`}
project={project}
/>
</DetailsView> </DetailsView>
)} )}
</Card> </Card>
......
...@@ -3,8 +3,8 @@ import { Icon, Button, th } from '@pubsweet/ui' ...@@ -3,8 +3,8 @@ import { Icon, Button, th } from '@pubsweet/ui'
import styled, { css, withTheme } from 'styled-components' import styled, { css, withTheme } from 'styled-components'
import { compose, withHandlers, lifecycle, withState } from 'recompose' import { compose, withHandlers, lifecycle, withState } from 'recompose'
import { import {
withModal,
ConfirmationModal, ConfirmationModal,
withModal2,
} from 'pubsweet-component-modal/src/components' } from 'pubsweet-component-modal/src/components'
import { ReviewerForm, ReviewersList } from './' import { ReviewerForm, ReviewersList } from './'
...@@ -69,10 +69,9 @@ const ModalSwitcher = ({ type, ...rest }) => { ...@@ -69,10 +69,9 @@ const ModalSwitcher = ({ type, ...rest }) => {
} }
export default compose( export default compose(
withModal({ withModal2(props => ({
modalKey: 'invite-reviewers',
modalComponent: ModalSwitcher, modalComponent: ModalSwitcher,
}), })),
withHandlers({ withHandlers({
showInviteModal: ({ showModal, hideModal, project, reviewers }) => () => { showInviteModal: ({ showModal, hideModal, project, reviewers }) => () => {
showModal({ showModal({
......
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