feat: fixing some error and remove axios instance in config
This commit is contained in:
parent
3fe4c4b995
commit
985cd0dc14
|
|
@ -47,13 +47,13 @@ export default function ContentProductionVisualization() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
const response1 = await generateTicket();
|
const response1 = await generateTicket();
|
||||||
setTicket1(response1.data?.data);
|
setTicket1(response1?.data?.data);
|
||||||
|
|
||||||
const response2 = await generateTicket();
|
const response2 = await generateTicket();
|
||||||
setTicket2(response2.data?.data);
|
setTicket2(response2?.data?.data);
|
||||||
|
|
||||||
const response3 = await generateTicket();
|
const response3 = await generateTicket();
|
||||||
setTicket3(response3.data?.data);
|
setTicket3(response3?.data?.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
initState();
|
initState();
|
||||||
|
|
|
||||||
|
|
@ -44,13 +44,13 @@ export default function DashboardVisualization() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
const response1 = await generateTicket();
|
const response1 = await generateTicket();
|
||||||
setTicket1(response1.data?.data);
|
setTicket1(response1?.data?.data);
|
||||||
console.log("response", response1);
|
console.log("response", response1);
|
||||||
const response2 = await generateTicket();
|
const response2 = await generateTicket();
|
||||||
setTicket2(response2.data?.data);
|
setTicket2(response2?.data?.data);
|
||||||
|
|
||||||
const response3 = await generateTicket();
|
const response3 = await generateTicket();
|
||||||
setTicket3(response3.data?.data);
|
setTicket3(response3?.data?.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
initState();
|
initState();
|
||||||
|
|
|
||||||
|
|
@ -55,16 +55,16 @@ export default function PatternRelationVisualization() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
const response1 = await generateTicket();
|
const response1 = await generateTicket();
|
||||||
setTicket1(response1.data?.data);
|
setTicket1(response1?.data?.data);
|
||||||
|
|
||||||
const response2 = await generateTicket();
|
const response2 = await generateTicket();
|
||||||
setTicket2(response2.data?.data);
|
setTicket2(response2?.data?.data);
|
||||||
|
|
||||||
const response3 = await generateTicket();
|
const response3 = await generateTicket();
|
||||||
setTicket3(response3.data?.data);
|
setTicket3(response3?.data?.data);
|
||||||
|
|
||||||
const response4 = await generateTicket();
|
const response4 = await generateTicket();
|
||||||
setTicket4(response4.data?.data);
|
setTicket4(response4?.data?.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
initState();
|
initState();
|
||||||
|
|
|
||||||
240
config/api.ts
240
config/api.ts
|
|
@ -1,240 +0,0 @@
|
||||||
"use client";
|
|
||||||
import axios from "axios";
|
|
||||||
import Cookies from "js-cookie";
|
|
||||||
import qs from "qs";
|
|
||||||
|
|
||||||
import axiosInstance from "./axiosInstance";
|
|
||||||
import axiosInstanceJson from "./axiosInstanceJson";
|
|
||||||
import { data } from "@/app/[locale]/(protected)/charts/rechart/charts-rechart-bar/data";
|
|
||||||
import { url } from "inspector";
|
|
||||||
|
|
||||||
const baseURL = "https://netidhub.com/api/";
|
|
||||||
const tokenAuth = Cookies.get("access_token")
|
|
||||||
? Cookies.get("access_token")
|
|
||||||
: null;
|
|
||||||
|
|
||||||
export async function postAPI(url: any, data: any) {
|
|
||||||
const headers = {
|
|
||||||
Authorization: `Bearer ${tokenAuth}`,
|
|
||||||
};
|
|
||||||
const response = await axiosInstance
|
|
||||||
.post(url, qs.stringify(data), { headers })
|
|
||||||
.catch((error) => error.response);
|
|
||||||
if (response?.status > 300) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data.error_description,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAPI(url: any, token: any) {
|
|
||||||
const headers = {
|
|
||||||
Authorization: `Bearer ${token || tokenAuth}`,
|
|
||||||
};
|
|
||||||
const response = await axios
|
|
||||||
.get(baseURL + url, { headers })
|
|
||||||
.catch((error) => error.response);
|
|
||||||
if (response?.status > 300) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.error_description,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function postAPIWithJson(url: any, data: any, token: any) {
|
|
||||||
const headers = {
|
|
||||||
Authorization: `Bearer ${token || tokenAuth}`,
|
|
||||||
};
|
|
||||||
const response = await axiosInstanceJson
|
|
||||||
.post(url, data, { headers })
|
|
||||||
.catch((error) => error.response);
|
|
||||||
if (response?.status > 300) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deleteAPIWithJson(url: any) {
|
|
||||||
const response = await axiosInstanceJson
|
|
||||||
.delete(url)
|
|
||||||
.catch((error) => error.response);
|
|
||||||
if (response?.status > 300) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAPIInterceptor(url: any) {
|
|
||||||
const response = await axiosInterceptor
|
|
||||||
.get(url)
|
|
||||||
.catch((error) => error.response);
|
|
||||||
if (response?.status == 401) {
|
|
||||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
|
||||||
Cookies.remove(cookieName);
|
|
||||||
});
|
|
||||||
// window.location.href = "/in/auth";
|
|
||||||
} else if (response?.status > 300 && response?.status != 401) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
} else if (response?.data.success) {
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message || null,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// Fungsi postAPIInterceptor
|
|
||||||
export async function postAPIInterceptor(url: string, data: any) {
|
|
||||||
const response = await axiosInterceptor
|
|
||||||
.post(url, data)
|
|
||||||
.catch((error) => error.response);
|
|
||||||
|
|
||||||
if (response?.status === 401) {
|
|
||||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
|
||||||
Cookies.remove(cookieName);
|
|
||||||
});
|
|
||||||
// window.location.href = "/";
|
|
||||||
} else if (response?.status > 300 && response?.status !== 401) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
} else if (response?.data?.success) {
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fungsi createTask
|
|
||||||
export async function createTask(data: any) {
|
|
||||||
const url = "assignment";
|
|
||||||
return postAPIInterceptor(url, data); // Perbaikan: Memisahkan parameter url dan data
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deleteAPIInterceptor(url: any, data: any) {
|
|
||||||
const response = await axiosInterceptor
|
|
||||||
.delete(url, { data })
|
|
||||||
.catch((error) => error.response);
|
|
||||||
if (response?.status == 401) {
|
|
||||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
|
||||||
Cookies.remove(cookieName);
|
|
||||||
});
|
|
||||||
// window.location.href = "/";
|
|
||||||
} else if (response?.status > 300 && response?.status != 401) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
} else if (response?.data.success) {
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAPIInterceptorProfile(url: any) {
|
|
||||||
const response = await axiosInterceptor
|
|
||||||
.get(url)
|
|
||||||
.catch((error) => error.response);
|
|
||||||
if (response?.status > 300) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: response?.data?.message,
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// export async function postFileApiInterceptor(url: any, data: any) {
|
|
||||||
// const response = await axiosInterceptor
|
|
||||||
// .post(url, data, {
|
|
||||||
// onUploadProgress: (progressEvent) => {
|
|
||||||
// const percentage = Math.round(
|
|
||||||
// (progressEvent.loaded * 100) / progressEvent.total
|
|
||||||
// );
|
|
||||||
// console.log(percentage);
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .catch((error) => error.response);
|
|
||||||
// if (response?.status > 300) {
|
|
||||||
// return {
|
|
||||||
// error: true,
|
|
||||||
// message: response?.data?.message,
|
|
||||||
// data: null,
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// if (response?.data.success) {
|
|
||||||
// return {
|
|
||||||
// error: false,
|
|
||||||
// message: "success",
|
|
||||||
// data: response?.data,
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// return {
|
|
||||||
// error: true,
|
|
||||||
// message: response?.data.message,
|
|
||||||
// data: null,
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
"use client";
|
|
||||||
import axios from "axios";
|
|
||||||
|
|
||||||
const baseURL = "https://netidhub.com/api/";
|
|
||||||
|
|
||||||
const axiosInstance = axios.create({
|
|
||||||
baseURL,
|
|
||||||
headers: {
|
|
||||||
"content-type": "application/x-www-form-urlencoded",
|
|
||||||
},
|
|
||||||
withCredentials: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default axiosInstance;
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
"use client";
|
|
||||||
import axios from "axios";
|
|
||||||
|
|
||||||
const baseURL = "https://netidhub.com/api/";
|
|
||||||
|
|
||||||
const axiosInstanceJson = axios.create({
|
|
||||||
baseURL,
|
|
||||||
headers: {
|
|
||||||
"content-type": "application/json",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default axiosInstanceJson;
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import axiosInstance from "@/config/axiosInstance";
|
|
||||||
import axiosBaseInstance from "./axios-base-instance";
|
import axiosBaseInstance from "./axios-base-instance";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue