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:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user