Fixed imports all components

This commit is contained in:
MaxOvs19
2023-05-30 10:10:34 +03:00
parent 3fc1faff5f
commit 11b91ef627
63 changed files with 286 additions and 284 deletions

View File

@ -1,7 +1,5 @@
import axios from 'axios';
import {getToken, urlHasParams} from "../helper";
import axios from "axios";
import { getToken, urlHasParams } from "../utils/helper";
const instance = axios.create({
baseURL: process.env.REACT_APP_API_URL,
@ -10,40 +8,47 @@ const instance = axios.create({
},
});
export const apiRequest = (url, {
method = 'get', params, data,
headers = {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
},
} = {}) => {
const fullHeaders = {...headers, ...getToken()};
export const apiRequest = (
url,
{
method = "get",
params,
data,
headers = {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
} = {}
) => {
const fullHeaders = { ...headers, ...getToken() };
let urWithParams = urlHasParams(url);
return instance
.request({
url: urWithParams,
method,
params,
data,
headers: {...fullHeaders},
})
.then(response => new Promise(resolve => {
if (response.data.redirect || response.status === 401) {
window.location.replace('/auth');
localStorage.clear();
// dispatch(auth(false));
}
return resolve(response)
}))
.then(response => new Promise(resolve => resolve(response.data)))
.request({
url: urWithParams,
method,
params,
data,
headers: { ...fullHeaders },
})
.then(
(response) =>
new Promise((resolve) => {
if (response.data.redirect || response.status === 401) {
window.location.replace("/auth");
localStorage.clear();
// dispatch(auth(false));
}
return resolve(response);
})
)
.then((response) => new Promise((resolve) => resolve(response.data)));
};
const RequestError = (code, msg, data) => {
const description = msg ? `- ${msg}` : '';
const description = msg ? `- ${msg}` : "";
this.name = 'RequestError';
this.name = "RequestError";
this.message = `API returned: ${code}${description}.`;
this.code = code;
this.description = msg;