1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-06-15 13:36:35 +02:00

Set tests.

This commit is contained in:
Bogdan Bodnar
2019-08-27 15:28:29 +02:00
parent 39a8c16824
commit 18e8e20206
18 changed files with 215 additions and 199 deletions

View File

@ -8,7 +8,7 @@
import axios from "axios";
import { useCallback, useReducer } from "react";
import { ForisUrls } from "forisUrls";
import { ForisURLs } from "forisUrls";
const POST_HEADERS = {
@ -57,7 +57,7 @@ const APIGetReducer = (state, action) => {
data: action.payload,
};
case API_ACTIONS.FAILURE:
if (action.status === 403) window.location.assign(ForisUrls.login);
if (action.status === 403) window.location.assign(ForisURLs.login);
return {
...state,
isLoading: false,
@ -69,18 +69,12 @@ const APIGetReducer = (state, action) => {
}
};
/**
* This function adds one to its input.
* @returns {number} that number, plus one.
* @param url
*/
export function useAPIGet(url) {
const [state, dispatch] = useReducer(APIGetReducer, {
isLoading: false,
isError: false,
data: null,
});
const get = useCallback(async () => {
dispatch({ type: API_ACTIONS.INIT });
try {
@ -118,7 +112,7 @@ const APIPostReducer = (state, action) => {
data: action.payload,
};
case API_ACTIONS.FAILURE:
if (action.status === 403) window.location.assign(ForisUrls.login);
if (action.status === 403) window.location.assign(ForisURLs.login);
return {
...state,
isSending: false,