mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Fixed wrong reducer being called
This commit is contained in:
parent
1dee478234
commit
b5de9bf523
3 changed files with 18 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue