mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Refactored tagDelete reducer to take advantage of redux-actions
This commit is contained in:
parent
740aacbbf1
commit
879034c9c6
1 changed files with 8 additions and 23 deletions
|
@ -1,11 +1,12 @@
|
|||
import { handleActions } from 'redux-actions';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
/* eslint-disable padding-line-between-statements, newline-after-var */
|
||||
/* eslint-disable padding-line-between-statements */
|
||||
export const DELETE_TAG_START = 'shlink/deleteTag/DELETE_TAG_START';
|
||||
export const DELETE_TAG_ERROR = 'shlink/deleteTag/DELETE_TAG_ERROR';
|
||||
export const DELETE_TAG = 'shlink/deleteTag/DELETE_TAG';
|
||||
export const TAG_DELETED = 'shlink/deleteTag/TAG_DELETED';
|
||||
/* eslint-enable padding-line-between-statements, newline-after-var */
|
||||
/* eslint-enable padding-line-between-statements */
|
||||
|
||||
export const tagDeleteType = PropTypes.shape({
|
||||
deleting: PropTypes.bool,
|
||||
|
@ -17,27 +18,11 @@ const defaultState = {
|
|||
error: false,
|
||||
};
|
||||
|
||||
export default function reducer(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case DELETE_TAG_START:
|
||||
return {
|
||||
deleting: true,
|
||||
error: false,
|
||||
};
|
||||
case DELETE_TAG_ERROR:
|
||||
return {
|
||||
deleting: false,
|
||||
error: true,
|
||||
};
|
||||
case DELETE_TAG:
|
||||
return {
|
||||
deleting: false,
|
||||
error: false,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
export default handleActions({
|
||||
[DELETE_TAG_START]: () => ({ deleting: true, error: false }),
|
||||
[DELETE_TAG_ERROR]: () => ({ deleting: false, error: true }),
|
||||
[DELETE_TAG]: () => ({ deleting: false, error: false }),
|
||||
}, defaultState);
|
||||
|
||||
export const deleteTag = (buildShlinkApiClient) => (tag) => async (dispatch, getState) => {
|
||||
dispatch({ type: DELETE_TAG_START });
|
||||
|
|
Loading…
Reference in a new issue