diff --git a/src/tags/helpers/DeleteTagConfirmModal.js b/src/tags/helpers/DeleteTagConfirmModal.js index e4138df3..59a4cb33 100644 --- a/src/tags/helpers/DeleteTagConfirmModal.js +++ b/src/tags/helpers/DeleteTagConfirmModal.js @@ -3,15 +3,13 @@ import { connect } from 'react-redux'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import PropTypes from 'prop-types'; import { pick } from 'ramda'; -import { deleteTag, tagDeleteType } from '../reducers/tagDelete'; -import { listTags } from '../reducers/tagsList'; +import { deleteTag, tagDeleted, tagDeleteType } from '../reducers/tagDelete'; const propTypes = { tag: PropTypes.string.isRequired, toggle: PropTypes.func.isRequired, isOpen: PropTypes.bool.isRequired, deleteTag: PropTypes.func, - listTags: PropTypes.func, tagDelete: tagDeleteType, }; @@ -19,20 +17,21 @@ export class DeleteTagConfirmModal extends Component { doDelete = () => { const { tag, toggle, deleteTag } = this.props; deleteTag(tag).then(() => { - this.tagDeleted = true; + this.tagWasDeleted = true; toggle(); - }).catch(() => {}); + }); }; onClosed = () => { - if (!this.tagDeleted) { + if (!this.tagWasDeleted) { return; } - this.props.listTags(); + const { tagDeleted, tag } = this.props; + tagDeleted(tag); }; componentDidMount() { - this.tagDeleted = false; + this.tagWasDeleted = false; } render() { @@ -70,5 +69,5 @@ DeleteTagConfirmModal.propTypes = propTypes; export default connect( pick(['tagDelete']), - { deleteTag, listTags } + { deleteTag, tagDeleted } )(DeleteTagConfirmModal); diff --git a/src/tags/reducers/tagDelete.js b/src/tags/reducers/tagDelete.js index 373c1b2d..c80d43f7 100644 --- a/src/tags/reducers/tagDelete.js +++ b/src/tags/reducers/tagDelete.js @@ -5,6 +5,7 @@ import PropTypes from 'prop-types'; const DELETE_TAG_START = 'shlink/deleteTag/DELETE_TAG_START'; const DELETE_TAG_ERROR = 'shlink/deleteTag/DELETE_TAG_ERROR'; const DELETE_TAG = 'shlink/deleteTag/DELETE_TAG'; +export const TAG_DELETED = 'shlink/deleteTag/TAG_DELETED'; export const tagDeleteType = PropTypes.shape({ deleting: PropTypes.bool, @@ -50,3 +51,5 @@ export const _deleteTag = (ShlinkApiClient, tag) => async dispatch => { } }; export const deleteTag = curry(_deleteTag)(ShlinkApiClient); + +export const tagDeleted = tag => ({ type: TAG_DELETED, tag }); diff --git a/src/tags/reducers/tagsList.js b/src/tags/reducers/tagsList.js index d0229ec2..80b9e448 100644 --- a/src/tags/reducers/tagsList.js +++ b/src/tags/reducers/tagsList.js @@ -1,4 +1,6 @@ import ShlinkApiClient from '../../api/ShlinkApiClient'; +import { TAG_DELETED } from './tagDelete'; +import { reject } from 'ramda'; const LIST_TAGS_START = 'shlink/tagsList/LIST_TAGS_START'; const LIST_TAGS_ERROR = 'shlink/tagsList/LIST_TAGS_ERROR'; @@ -30,6 +32,11 @@ export default function reducer(state = defaultState, action) { loading: false, error: false, }; + case TAG_DELETED: + return { + ...state, + tags: reject(tag => tag === action.tag, state.tags), + }; default: return state; }