mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 17:57:26 +03:00
Refactored shortUrlCreation reducer to takle advantage of redux-actions
This commit is contained in:
parent
4894ab9035
commit
3075ccb4b9
1 changed files with 8 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
||||||
import PropTypes from 'prop-types';
|
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, newline-after-var */
|
||||||
export const CREATE_SHORT_URL_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START';
|
export const CREATE_SHORT_URL_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START';
|
||||||
|
@ -21,32 +22,12 @@ const defaultState = {
|
||||||
error: false,
|
error: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action) {
|
export default handleActions({
|
||||||
switch (action.type) {
|
[CREATE_SHORT_URL_START]: (state) => ({ ...state, saving: true, error: false }),
|
||||||
case CREATE_SHORT_URL_START:
|
[CREATE_SHORT_URL_ERROR]: (state) => ({ ...state, saving: false, error: true }),
|
||||||
return {
|
[CREATE_SHORT_URL]: (state, { result }) => ({ result, saving: false, error: false }),
|
||||||
...state,
|
[RESET_CREATE_SHORT_URL]: () => defaultState,
|
||||||
saving: true,
|
}, defaultState);
|
||||||
error: false,
|
|
||||||
};
|
|
||||||
case CREATE_SHORT_URL_ERROR:
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
saving: false,
|
|
||||||
error: true,
|
|
||||||
};
|
|
||||||
case CREATE_SHORT_URL:
|
|
||||||
return {
|
|
||||||
result: action.result,
|
|
||||||
saving: false,
|
|
||||||
error: false,
|
|
||||||
};
|
|
||||||
case RESET_CREATE_SHORT_URL:
|
|
||||||
return defaultState;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const createShortUrl = (buildShlinkApiClient) => (data) => async (dispatch, getState) => {
|
export const createShortUrl = (buildShlinkApiClient) => (data) => async (dispatch, getState) => {
|
||||||
dispatch({ type: CREATE_SHORT_URL_START });
|
dispatch({ type: CREATE_SHORT_URL_START });
|
||||||
|
@ -63,4 +44,4 @@ export const createShortUrl = (buildShlinkApiClient) => (data) => async (dispatc
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resetCreateShortUrl = () => ({ type: RESET_CREATE_SHORT_URL });
|
export const resetCreateShortUrl = createAction(RESET_CREATE_SHORT_URL);
|
||||||
|
|
Loading…
Reference in a new issue