mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-08-03 01:21:54 +00:00
Connected creation form with redux, and created reducer for short URL creation
This commit is contained in:
46
src/short-urls/reducers/shortUrlCreationResult.js
Normal file
46
src/short-urls/reducers/shortUrlCreationResult.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import ShlinkApiClient from '../../api/ShlinkApiClient';
|
||||
|
||||
const CREATE_SHORT_URL_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START';
|
||||
const CREATE_SHORT_URL_ERROR = 'shlink/createShortUrl/CREATE_SHORT_URL_ERROR';
|
||||
const CREATE_SHORT_URL = 'shlink/createShortUrl/CREATE_SHORT_URL';
|
||||
|
||||
const defaultState = {
|
||||
result: null,
|
||||
saving: false,
|
||||
error: false,
|
||||
};
|
||||
|
||||
export default function reducer(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case CREATE_SHORT_URL_START:
|
||||
return {
|
||||
...state,
|
||||
saving: true,
|
||||
};
|
||||
case CREATE_SHORT_URL_ERROR:
|
||||
return {
|
||||
...state,
|
||||
saving: false,
|
||||
error: true,
|
||||
};
|
||||
case CREATE_SHORT_URL:
|
||||
return {
|
||||
result: action.result,
|
||||
saving: false,
|
||||
error: true,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export const createShortUrl = data => async dispatch => {
|
||||
dispatch({ type: CREATE_SHORT_URL_START });
|
||||
|
||||
try {
|
||||
const result = await ShlinkApiClient.createShortUrl(data);
|
||||
dispatch({ type: CREATE_SHORT_URL, result });
|
||||
} catch (e) {
|
||||
dispatch({ type: CREATE_SHORT_URL_ERROR });
|
||||
}
|
||||
};
|
||||
@@ -41,15 +41,13 @@ export const listShortUrls = (serverId, params = {}) => {
|
||||
return updateShortUrlsList(params);
|
||||
};
|
||||
|
||||
export const updateShortUrlsList = (params = {}) => {
|
||||
return async dispatch => {
|
||||
dispatch({ type: LIST_SHORT_URLS_START });
|
||||
export const updateShortUrlsList = (params = {}) => async dispatch => {
|
||||
dispatch({ type: LIST_SHORT_URLS_START });
|
||||
|
||||
try {
|
||||
const shortUrls = await ShlinkApiClient.listShortUrls(params);
|
||||
dispatch({ type: LIST_SHORT_URLS, shortUrls, params });
|
||||
} catch (e) {
|
||||
dispatch({ type: LIST_SHORT_URLS_ERROR, params });
|
||||
}
|
||||
};
|
||||
try {
|
||||
const shortUrls = await ShlinkApiClient.listShortUrls(params);
|
||||
dispatch({ type: LIST_SHORT_URLS, shortUrls, params });
|
||||
} catch (e) {
|
||||
dispatch({ type: LIST_SHORT_URLS_ERROR, params });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user