mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 01:37:24 +03:00
Refactored tagEdit reducer to take advantage of redux-actions
This commit is contained in:
parent
879034c9c6
commit
5bb9d15e27
3 changed files with 16 additions and 30 deletions
|
@ -1,12 +1,12 @@
|
|||
import PropTypes from 'prop-types';
|
||||
import { createAction, handleActions } from 'redux-actions';
|
||||
|
||||
/* eslint-disable padding-line-between-statements, newline-after-var */
|
||||
/* eslint-disable padding-line-between-statements */
|
||||
export const CREATE_SHORT_URL_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START';
|
||||
export const CREATE_SHORT_URL_ERROR = 'shlink/createShortUrl/CREATE_SHORT_URL_ERROR';
|
||||
export const CREATE_SHORT_URL = 'shlink/createShortUrl/CREATE_SHORT_URL';
|
||||
export const RESET_CREATE_SHORT_URL = 'shlink/createShortUrl/RESET_CREATE_SHORT_URL';
|
||||
/* eslint-enable padding-line-between-statements, newline-after-var */
|
||||
/* eslint-enable padding-line-between-statements */
|
||||
|
||||
export const createShortUrlResultType = PropTypes.shape({
|
||||
result: PropTypes.shape({
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { createAction, 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_SHORT_URL_START = 'shlink/deleteShortUrl/DELETE_SHORT_URL_START';
|
||||
export const DELETE_SHORT_URL_ERROR = 'shlink/deleteShortUrl/DELETE_SHORT_URL_ERROR';
|
||||
export const DELETE_SHORT_URL = 'shlink/deleteShortUrl/DELETE_SHORT_URL';
|
||||
export const RESET_DELETE_SHORT_URL = 'shlink/deleteShortUrl/RESET_DELETE_SHORT_URL';
|
||||
export const SHORT_URL_DELETED = 'shlink/deleteShortUrl/SHORT_URL_DELETED';
|
||||
/* eslint-enable padding-line-between-statements, newline-after-var */
|
||||
/* eslint-enable padding-line-between-statements */
|
||||
|
||||
export const shortUrlDeletionType = PropTypes.shape({
|
||||
shortCode: PropTypes.string.isRequired,
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { pick } from 'ramda';
|
||||
import { handleActions } from 'redux-actions';
|
||||
|
||||
/* eslint-disable padding-line-between-statements, newline-after-var */
|
||||
/* eslint-disable padding-line-between-statements */
|
||||
export const EDIT_TAG_START = 'shlink/editTag/EDIT_TAG_START';
|
||||
export const EDIT_TAG_ERROR = 'shlink/editTag/EDIT_TAG_ERROR';
|
||||
export const EDIT_TAG = 'shlink/editTag/EDIT_TAG';
|
||||
/* eslint-enable padding-line-between-statements, newline-after-var */
|
||||
/* eslint-enable padding-line-between-statements */
|
||||
|
||||
export const TAG_EDITED = 'shlink/editTag/TAG_EDITED';
|
||||
|
||||
|
@ -15,30 +16,15 @@ const defaultState = {
|
|||
error: false,
|
||||
};
|
||||
|
||||
export default function reducer(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case EDIT_TAG_START:
|
||||
return {
|
||||
...state,
|
||||
editing: true,
|
||||
error: false,
|
||||
};
|
||||
case EDIT_TAG_ERROR:
|
||||
return {
|
||||
...state,
|
||||
editing: false,
|
||||
error: true,
|
||||
};
|
||||
case EDIT_TAG:
|
||||
return {
|
||||
...pick([ 'oldName', 'newName' ], action),
|
||||
editing: false,
|
||||
error: false,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
export default handleActions({
|
||||
[EDIT_TAG_START]: (state) => ({ ...state, editing: true, error: false }),
|
||||
[EDIT_TAG_ERROR]: (state) => ({ ...state, editing: false, error: true }),
|
||||
[EDIT_TAG]: (state, action) => ({
|
||||
...pick([ 'oldName', 'newName' ], action),
|
||||
editing: false,
|
||||
error: false,
|
||||
}),
|
||||
}, defaultState);
|
||||
|
||||
export const editTag = (buildShlinkApiClient, colorGenerator) => (oldName, newName, color) => async (
|
||||
dispatch,
|
||||
|
|
Loading…
Reference in a new issue