Defined visit stats page

This commit is contained in:
Alejandro Celaya
2018-07-29 19:25:22 +02:00
parent c02b0e0591
commit a75c7309f7
8 changed files with 87 additions and 31 deletions

View File

@@ -0,0 +1,46 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
const GET_SHORT_URL_VISITS_START = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS_START';
const GET_SHORT_URL_VISITS_ERROR = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS_ERROR';
const GET_SHORT_URL_VISITS = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS';
const initialState = {
visits: [],
loading: false,
error: false
};
export default function dispatch (state = initialState, action) {
switch (action.type) {
case GET_SHORT_URL_VISITS_START:
return {
...state,
loading: true
};
case GET_SHORT_URL_VISITS_ERROR:
return {
...state,
loading: false,
error: true
};
case GET_SHORT_URL_VISITS:
return {
visits: action.visits,
loading: false,
error: false
};
default:
return state;
}
}
export const getShortUrlVisits = shortCode => async dispatch => {
dispatch({ type: GET_SHORT_URL_VISITS_START });
try {
const visits = await ShlinkApiClient.getShortUrlVisits(shortCode);
dispatch({ visits, type: GET_SHORT_URL_VISITS });
} catch (e) {
dispatch({ type: GET_SHORT_URL_VISITS_ERROR });
}
};

View File

@@ -1,10 +1,8 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
import ServersService from '../../servers/services/ServersService';
export const LIST_SHORT_URLS_START = 'shlink/shortUrlsList/LIST_SHORT_URLS_START';
export const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR';
const LIST_SHORT_URLS_START = 'shlink/shortUrlsList/LIST_SHORT_URLS_START';
const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR';
export const LIST_SHORT_URLS = 'shlink/shortUrlsList/LIST_SHORT_URLS';
export const UPDATE_SHORT_URLS_LIST = LIST_SHORT_URLS;
const initialState = {
shortUrls: [],
@@ -32,16 +30,7 @@ export default function reducer(state = initialState, action) {
}
}
export const listShortUrls = (serverId, params = {}) => {
// FIXME There should be a way to not need this, however, the active server is set when any route is loaded, in an
// FIXME outer component's componentDidMount, which makes it be invoked after this action
const selectedServer = ServersService.findServerById(serverId);
ShlinkApiClient.setConfig(selectedServer);
return updateShortUrlsList(params);
};
export const updateShortUrlsList = (params = {}) => async dispatch => {
export const listShortUrls = (params = {}) => async dispatch => {
dispatch({ type: LIST_SHORT_URLS_START });
try {

View File

@@ -1,8 +1,7 @@
import { UPDATE_SHORT_URLS_LIST, LIST_SHORT_URLS } from './shortUrlsList';
import { LIST_SHORT_URLS } from './shortUrlsList';
export default function reducer(state = { page: 1 }, action) {
switch (action.type) {
case UPDATE_SHORT_URLS_LIST:
case LIST_SHORT_URLS:
return { ...state, ...action.params };
default: