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

fix(deleteManuscript): fix delete manucript front end

parent bfdf11d6
No related branches found
No related tags found
2 merge requests!136Sprint 22 features (updates),!125HIN-1066
......@@ -78,7 +78,7 @@ const Root = styled.div`
${marginHelper};
${paddingHelper};
height: max-content;
height: ${props => (props.height ? `${props.height}px` : 'max-content')};
width: max-content;
& span {
......
......@@ -24,6 +24,7 @@ import { OpenModal } from './modals'
const ManuscriptCard = ({
onDelete,
canDelete,
isFetching,
onCardClick,
canViewReports,
fragment = {},
......@@ -87,16 +88,17 @@ const ManuscriptCard = ({
<Item justify="flex-end" onClick={e => e.stopPropagation()}>
<OpenModal
confirmText="Delete"
isFetching={isFetching}
modalKey={`delete-${collId}`}
onConfirm={onDelete}
title="Are you sure you want to delete this submission?"
>
{onClickEvent => (
{showModal => (
<ActionLink
height={16}
icon="trash"
onClick={onClickEvent}
onClick={showModal}
size="small"
style={{ height: 16 }}
>
Delete
</ActionLink>
......
......@@ -4,12 +4,13 @@ import { compose, withProps } from 'recompose'
import { DashboardItems, DashboardFilters } from './'
const Dashboard = ({
deleteProject,
journal,
isFetching,
dashboardItems,
deleteCollection,
getFilterOptions,
changeFilterValue,
getDefaultFilterValue,
journal,
}) => (
<Fragment>
<DashboardFilters
......@@ -17,7 +18,11 @@ const Dashboard = ({
getDefaultFilterValue={getDefaultFilterValue}
getFilterOptions={getFilterOptions}
/>
<DashboardItems deleteProject={deleteProject} list={dashboardItems} />
<DashboardItems
deleteCollection={deleteCollection}
isFetching={isFetching}
list={dashboardItems}
/>
</Fragment>
)
......
......@@ -5,9 +5,9 @@ import { connect } from 'react-redux'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { withRouter } from 'react-router-dom'
import { compose, setDisplayName, withHandlers, withProps } from 'recompose'
import { ManuscriptCard, Row } from 'pubsweet-component-faraday-ui'
import { canViewReports } from 'pubsweet-component-faraday-selectors'
import { compose, setDisplayName, withHandlers, withProps } from 'recompose'
const DashboardItem = compose(
connect((state, { collection }) => ({
......@@ -18,7 +18,13 @@ const DashboardItem = compose(
})),
)(ManuscriptCard)
const DashboardItems = ({ list, onClick, deleteProject, canViewReports }) => (
const DashboardItems = ({
list,
onClick,
isFetching,
canViewReports,
deleteCollection,
}) => (
<Root data-test-id="dashboard-list-items">
{!list.length ? (
<Row justify="center" mt={4}>
......@@ -29,9 +35,10 @@ const DashboardItems = ({ list, onClick, deleteProject, canViewReports }) => (
<HideLoading key={collection.id}>
<DashboardItem
collection={collection}
isFetching={isFetching}
key={collection.id}
onClick={onClick}
onDelete={() => deleteProject(collection)}
onDelete={deleteCollection(collection)}
/>
</HideLoading>
))
......
......@@ -4,8 +4,9 @@ import { actions } from 'pubsweet-client'
import { withJournal } from 'xpub-journal'
import { ConnectPage } from 'xpub-connect'
import { withRouter } from 'react-router-dom'
import { compose, withContext } from 'recompose'
import { selectCurrentUser } from 'xpub-selectors'
import { compose, withHandlers, withContext } from 'recompose'
import { handleError, withFetching } from 'pubsweet-component-faraday-ui'
import {
getUserPermissions,
......@@ -32,13 +33,13 @@ export default compose(
userPermissions,
}
},
dispatch => ({
deleteProject: collection =>
dispatch(actions.deleteCollection(collection)),
}),
{
deleteCollection: actions.deleteCollection,
},
),
withRouter,
withJournal,
withFetching,
withFiltersHOC({
priority: priorityFilter,
order: orderFilter,
......@@ -50,4 +51,23 @@ export default compose(
},
({ journal, currentUser }) => ({ journal, currentUser }),
),
withHandlers({
deleteCollection: ({ setFetching, deleteCollection }) => collection => ({
hideModal,
setModalError,
}) => {
setFetching(true)
deleteCollection(collection)
.then(() => {
setFetching(false)
hideModal()
})
// again, the error is not being thrown from deleteCollection action and
// the catch is never run
.catch(err => {
setFetching(false)
handleError(setModalError)(err)
})
},
}),
)(Dashboard)
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