Updated behavior on tags modal so that the component handles all actions

This commit is contained in:
Alejandro Celaya
2018-08-15 19:10:35 +02:00
parent a1eadf767e
commit 03113583f0
3 changed files with 44 additions and 8 deletions

View File

@@ -1,11 +1,11 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
import { curry } from 'ramda';
import PropTypes from 'prop-types';
import { _listShortUrls } from './shortUrlsList';
export const EDIT_SHORT_URL_TAGS_START = 'shlink/shortUrlTags/EDIT_SHORT_URL_TAGS_START';
export const EDIT_SHORT_URL_TAGS_ERROR = 'shlink/shortUrlTags/EDIT_SHORT_URL_TAGS_ERROR';
export const EDIT_SHORT_URL_TAGS = 'shlink/shortUrlTags/EDIT_SHORT_URL_TAGS';
export const RESET_EDIT_SHORT_URL_TAGS = 'shlink/shortUrlTags/RESET_EDIT_SHORT_URL_TAGS';
export const shortUrlTagsType = PropTypes.shape({
shortCode: PropTypes.string,
@@ -42,6 +42,8 @@ export default function reducer(state = defaultState, action) {
saving: false,
error: false,
};
case RESET_EDIT_SHORT_URL_TAGS:
return defaultState;
default:
return state;
}
@@ -51,13 +53,14 @@ export const _editShortUrlTags = (ShlinkApiClient, shortCode, tags) => async (di
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
try {
// Update short URL tags
await ShlinkApiClient.updateShortUrlTags(shortCode, tags);
dispatch({ tags, shortCode, type: EDIT_SHORT_URL_TAGS });
const { shortUrlsListParams } = getState();
await _listShortUrls(ShlinkApiClient, shortUrlsListParams)(dispatch);
} catch (e) {
dispatch({ type: EDIT_SHORT_URL_TAGS_ERROR });
throw e;
}
};
export const editShortUrlTags = curry(_editShortUrlTags)(ShlinkApiClient);
export const resetShortUrlsTags = () => ({ type: RESET_EDIT_SHORT_URL_TAGS });

View File

@@ -41,3 +41,9 @@ export const _listShortUrls = (ShlinkApiClient, params = {}) => async dispatch =
}
};
export const listShortUrls = (params = {}) => _listShortUrls(ShlinkApiClient, params);
export const _refreshShortUrls = ShlinkApiClient => async (dispatch, getState) => {
const { shortUrlsListParams } = getState();
await _listShortUrls(ShlinkApiClient, shortUrlsListParams)(dispatch);
};
export const refreshShortUrls = () => _refreshShortUrls(ShlinkApiClient);