mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 02:07:26 +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 PropTypes from 'prop-types';
|
||||||
import { createAction, handleActions } from 'redux-actions';
|
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_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START';
|
||||||
export const CREATE_SHORT_URL_ERROR = 'shlink/createShortUrl/CREATE_SHORT_URL_ERROR';
|
export const CREATE_SHORT_URL_ERROR = 'shlink/createShortUrl/CREATE_SHORT_URL_ERROR';
|
||||||
export const CREATE_SHORT_URL = 'shlink/createShortUrl/CREATE_SHORT_URL';
|
export const CREATE_SHORT_URL = 'shlink/createShortUrl/CREATE_SHORT_URL';
|
||||||
export const RESET_CREATE_SHORT_URL = 'shlink/createShortUrl/RESET_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({
|
export const createShortUrlResultType = PropTypes.shape({
|
||||||
result: PropTypes.shape({
|
result: PropTypes.shape({
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { createAction, handleActions } from 'redux-actions';
|
import { createAction, 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_SHORT_URL_START = 'shlink/deleteShortUrl/DELETE_SHORT_URL_START';
|
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_ERROR = 'shlink/deleteShortUrl/DELETE_SHORT_URL_ERROR';
|
||||||
export const DELETE_SHORT_URL = 'shlink/deleteShortUrl/DELETE_SHORT_URL';
|
export const DELETE_SHORT_URL = 'shlink/deleteShortUrl/DELETE_SHORT_URL';
|
||||||
export const RESET_DELETE_SHORT_URL = 'shlink/deleteShortUrl/RESET_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';
|
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({
|
export const shortUrlDeletionType = PropTypes.shape({
|
||||||
shortCode: PropTypes.string.isRequired,
|
shortCode: PropTypes.string.isRequired,
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { pick } from 'ramda';
|
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_START = 'shlink/editTag/EDIT_TAG_START';
|
||||||
export const EDIT_TAG_ERROR = 'shlink/editTag/EDIT_TAG_ERROR';
|
export const EDIT_TAG_ERROR = 'shlink/editTag/EDIT_TAG_ERROR';
|
||||||
export const EDIT_TAG = 'shlink/editTag/EDIT_TAG';
|
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';
|
export const TAG_EDITED = 'shlink/editTag/TAG_EDITED';
|
||||||
|
|
||||||
|
@ -15,30 +16,15 @@ const defaultState = {
|
||||||
error: false,
|
error: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action) {
|
export default handleActions({
|
||||||
switch (action.type) {
|
[EDIT_TAG_START]: (state) => ({ ...state, editing: true, error: false }),
|
||||||
case EDIT_TAG_START:
|
[EDIT_TAG_ERROR]: (state) => ({ ...state, editing: false, error: true }),
|
||||||
return {
|
[EDIT_TAG]: (state, action) => ({
|
||||||
...state,
|
|
||||||
editing: true,
|
|
||||||
error: false,
|
|
||||||
};
|
|
||||||
case EDIT_TAG_ERROR:
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
editing: false,
|
|
||||||
error: true,
|
|
||||||
};
|
|
||||||
case EDIT_TAG:
|
|
||||||
return {
|
|
||||||
...pick([ 'oldName', 'newName' ], action),
|
...pick([ 'oldName', 'newName' ], action),
|
||||||
editing: false,
|
editing: false,
|
||||||
error: false,
|
error: false,
|
||||||
};
|
}),
|
||||||
default:
|
}, defaultState);
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const editTag = (buildShlinkApiClient, colorGenerator) => (oldName, newName, color) => async (
|
export const editTag = (buildShlinkApiClient, colorGenerator) => (oldName, newName, color) => async (
|
||||||
dispatch,
|
dispatch,
|
||||||
|
|
Loading…
Reference in a new issue