1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-08-01 20:03:28 +02:00

Client configuration

This commit is contained in:
Maciej Lenartowicz
2019-10-10 15:25:00 +00:00
parent 30748fab12
commit e3a795e40d
14 changed files with 170 additions and 120 deletions

View File

@@ -12,7 +12,7 @@ import {
API_ACTIONS, TIMEOUT, HEADERS, APIReducer, getErrorMessage,
} from "./utils";
export function useAPIPost(url) {
export function useAPIPost(url, contentType) {
const [state, dispatch] = useReducer(APIReducer, {
isSending: false,
isError: false,
@@ -20,12 +20,17 @@ export function useAPIPost(url) {
data: null,
});
const headers = { ...HEADERS };
if (contentType) {
headers["Content-Type"] = contentType;
}
const post = async (data) => {
dispatch({ type: API_ACTIONS.INIT });
try {
const result = await axios.post(url, data, {
timeout: TIMEOUT,
headers: HEADERS,
headers,
});
dispatch({ type: API_ACTIONS.SUCCESS, payload: result.data });
} catch (error) {