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

add spinner to confirmations modals

parent 0d788843
No related branches found
No related tags found
No related merge requests found
import React from 'react' import React from 'react'
import { Icon, Button, th } from '@pubsweet/ui'
import { compose, withHandlers } from 'recompose' import { compose, withHandlers } from 'recompose'
import { Icon, Button, th, Spinner } from '@pubsweet/ui'
import styled, { css, withTheme } from 'styled-components' import styled, { css, withTheme } from 'styled-components'
const ConfirmationModal = ({ const ConfirmationModal = ({
...@@ -13,6 +13,7 @@ const ConfirmationModal = ({ ...@@ -13,6 +13,7 @@ const ConfirmationModal = ({
cancelText = 'Cancel', cancelText = 'Cancel',
theme, theme,
modalError, modalError,
isFetching,
}) => ( }) => (
<Root> <Root>
<CloseIcon data-test="icon-modal-hide" onClick={onClose}> <CloseIcon data-test="icon-modal-hide" onClick={onClose}>
...@@ -28,11 +29,16 @@ const ConfirmationModal = ({ ...@@ -28,11 +29,16 @@ const ConfirmationModal = ({
<Button data-test="button-modal-hide" onClick={onClose}> <Button data-test="button-modal-hide" onClick={onClose}>
{cancelText} {cancelText}
</Button> </Button>
{onConfirm && ( {onConfirm &&
<Button data-test="button-modal-confirm" onClick={onConfirm} primary> (isFetching ? (
{confirmText} <SpinnerContainer>
</Button> <Spinner size={4} />
)} </SpinnerContainer>
) : (
<Button data-test="button-modal-confirm" onClick={onConfirm} primary>
{confirmText}
</Button>
))}
</ButtonsContainer> </ButtonsContainer>
</Root> </Root>
) )
...@@ -57,6 +63,14 @@ const defaultText = css` ...@@ -57,6 +63,14 @@ const defaultText = css`
font-size: ${th('fontSizeBaseSmall')}; font-size: ${th('fontSizeBaseSmall')};
` `
const SpinnerContainer = styled.div`
align-items: center;
display: flex;
justify-content: center;
height: calc(${th('gridUnit')} * 2);
min-width: calc(${th('gridUnit')} * 4);
`
const Root = styled.div` const Root = styled.div`
background-color: ${th('backgroundColor')}; background-color: ${th('backgroundColor')};
border: ${th('borderDefault')}; border: ${th('borderDefault')};
......
...@@ -84,14 +84,18 @@ const InviteReviewersModal = compose( ...@@ -84,14 +84,18 @@ const InviteReviewersModal = compose(
), ),
) )
const ModalSwitcher = ({ type, ...rest }) => { const ModalSwitcher = compose(
connect(state => ({
fetchingInvite: selectFechingInvite(state),
})),
)(({ type, fetchingInvite, ...rest }) => {
switch (type) { switch (type) {
case 'invite-reviewers': case 'invite-reviewers':
return <InviteReviewersModal {...rest} /> return <InviteReviewersModal {...rest} />
default: default:
return <ConfirmationModal {...rest} /> return <ConfirmationModal {...rest} isFetching={fetchingInvite} />
} }
} })
export default compose( export default compose(
withModal2(props => ({ withModal2(props => ({
......
...@@ -68,8 +68,12 @@ export const inviteReviewer = (reviewerData, collectionId) => dispatch => { ...@@ -68,8 +68,12 @@ export const inviteReviewer = (reviewerData, collectionId) => dispatch => {
}).then(() => dispatch(inviteSuccess()), err => dispatch(inviteError(err))) }).then(() => dispatch(inviteSuccess()), err => dispatch(inviteError(err)))
} }
export const revokeReviewer = (invitationId, collectionId) => dispatch => export const revokeReviewer = (invitationId, collectionId) => dispatch => {
remove(`/collections/${collectionId}/invitations/${invitationId}`) dispatch(inviteRequest())
return remove(
`/collections/${collectionId}/invitations/${invitationId}`,
).then(() => dispatch(inviteSuccess()), err => dispatch(inviteError(err)))
}
export default (state = initialState, action = {}) => { export default (state = initialState, action = {}) => {
switch (action.type) { switch (action.type) {
......
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