Fixed wrong reducer being called

This commit is contained in:
Alejandro Celaya 2018-08-18 16:47:19 +02:00
parent 1dee478234
commit b5de9bf523
3 changed files with 18 additions and 9 deletions

View file

@ -3,15 +3,13 @@ import { connect } from 'react-redux';
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { pick } from 'ramda'; import { pick } from 'ramda';
import { deleteTag, tagDeleteType } from '../reducers/tagDelete'; import { deleteTag, tagDeleted, tagDeleteType } from '../reducers/tagDelete';
import { listTags } from '../reducers/tagsList';
const propTypes = { const propTypes = {
tag: PropTypes.string.isRequired, tag: PropTypes.string.isRequired,
toggle: PropTypes.func.isRequired, toggle: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired, isOpen: PropTypes.bool.isRequired,
deleteTag: PropTypes.func, deleteTag: PropTypes.func,
listTags: PropTypes.func,
tagDelete: tagDeleteType, tagDelete: tagDeleteType,
}; };
@ -19,20 +17,21 @@ export class DeleteTagConfirmModal extends Component {
doDelete = () => { doDelete = () => {
const { tag, toggle, deleteTag } = this.props; const { tag, toggle, deleteTag } = this.props;
deleteTag(tag).then(() => { deleteTag(tag).then(() => {
this.tagDeleted = true; this.tagWasDeleted = true;
toggle(); toggle();
}).catch(() => {}); });
}; };
onClosed = () => { onClosed = () => {
if (!this.tagDeleted) { if (!this.tagWasDeleted) {
return; return;
} }
this.props.listTags(); const { tagDeleted, tag } = this.props;
tagDeleted(tag);
}; };
componentDidMount() { componentDidMount() {
this.tagDeleted = false; this.tagWasDeleted = false;
} }
render() { render() {
@ -70,5 +69,5 @@ DeleteTagConfirmModal.propTypes = propTypes;
export default connect( export default connect(
pick(['tagDelete']), pick(['tagDelete']),
{ deleteTag, listTags } { deleteTag, tagDeleted }
)(DeleteTagConfirmModal); )(DeleteTagConfirmModal);

View file

@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
const DELETE_TAG_START = 'shlink/deleteTag/DELETE_TAG_START'; const DELETE_TAG_START = 'shlink/deleteTag/DELETE_TAG_START';
const DELETE_TAG_ERROR = 'shlink/deleteTag/DELETE_TAG_ERROR'; const DELETE_TAG_ERROR = 'shlink/deleteTag/DELETE_TAG_ERROR';
const DELETE_TAG = 'shlink/deleteTag/DELETE_TAG'; const DELETE_TAG = 'shlink/deleteTag/DELETE_TAG';
export const TAG_DELETED = 'shlink/deleteTag/TAG_DELETED';
export const tagDeleteType = PropTypes.shape({ export const tagDeleteType = PropTypes.shape({
deleting: PropTypes.bool, deleting: PropTypes.bool,
@ -50,3 +51,5 @@ export const _deleteTag = (ShlinkApiClient, tag) => async dispatch => {
} }
}; };
export const deleteTag = curry(_deleteTag)(ShlinkApiClient); export const deleteTag = curry(_deleteTag)(ShlinkApiClient);
export const tagDeleted = tag => ({ type: TAG_DELETED, tag });

View file

@ -1,4 +1,6 @@
import ShlinkApiClient from '../../api/ShlinkApiClient'; 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_START = 'shlink/tagsList/LIST_TAGS_START';
const LIST_TAGS_ERROR = 'shlink/tagsList/LIST_TAGS_ERROR'; const LIST_TAGS_ERROR = 'shlink/tagsList/LIST_TAGS_ERROR';
@ -30,6 +32,11 @@ export default function reducer(state = defaultState, action) {
loading: false, loading: false,
error: false, error: false,
}; };
case TAG_DELETED:
return {
...state,
tags: reject(tag => tag === action.tag, state.tags),
};
default: default:
return state; return state;
} }