mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +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';
|
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_START = 'shlink/deleteTag/DELETE_TAG_START';
|
||||||
export const DELETE_TAG_ERROR = 'shlink/deleteTag/DELETE_TAG_ERROR';
|
export const DELETE_TAG_ERROR = 'shlink/deleteTag/DELETE_TAG_ERROR';
|
||||||
export const DELETE_TAG = 'shlink/deleteTag/DELETE_TAG';
|
export const DELETE_TAG = 'shlink/deleteTag/DELETE_TAG';
|
||||||
export const TAG_DELETED = 'shlink/deleteTag/TAG_DELETED';
|
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({
|
export const tagDeleteType = PropTypes.shape({
|
||||||
deleting: PropTypes.bool,
|
deleting: PropTypes.bool,
|
||||||
|
@ -17,27 +18,11 @@ const defaultState = {
|
||||||
error: false,
|
error: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action) {
|
export default handleActions({
|
||||||
switch (action.type) {
|
[DELETE_TAG_START]: () => ({ deleting: true, error: false }),
|
||||||
case DELETE_TAG_START:
|
[DELETE_TAG_ERROR]: () => ({ deleting: false, error: true }),
|
||||||
return {
|
[DELETE_TAG]: () => ({ deleting: false, error: false }),
|
||||||
deleting: true,
|
}, defaultState);
|
||||||
error: false,
|
|
||||||
};
|
|
||||||
case DELETE_TAG_ERROR:
|
|
||||||
return {
|
|
||||||
deleting: false,
|
|
||||||
error: true,
|
|
||||||
};
|
|
||||||
case DELETE_TAG:
|
|
||||||
return {
|
|
||||||
deleting: false,
|
|
||||||
error: false,
|
|
||||||
};
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const deleteTag = (buildShlinkApiClient) => (tag) => async (dispatch, getState) => {
|
export const deleteTag = (buildShlinkApiClient) => (tag) => async (dispatch, getState) => {
|
||||||
dispatch({ type: DELETE_TAG_START });
|
dispatch({ type: DELETE_TAG_START });
|
||||||
|
|
Loading…
Reference in a new issue