fix get return type
This commit is contained in:
1 parent
a11d551a99
commit
00cf0b6521
3 files changed
+6
-13
No files matched your search
+1
-1
@@ -43,7 +43,7 @@
|
|||||||
"react-toastify": "^10.0.5",
|
"react-toastify": "^10.0.5",
|
||||||
"recharts": "2.15.2",
|
"recharts": "2.15.2",
|
||||||
"redux-persist": "6.0.0",
|
"redux-persist": "6.0.0",
|
||||||
"swr": "2.3.6",
|
"swr": "^2.3.6",
|
||||||
"vite-plugin-svgr": "^4.2.0",
|
"vite-plugin-svgr": "^4.2.0",
|
||||||
"zod": "4.1.11"
|
"zod": "4.1.11"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import type { SWRConfiguration } from "swr";
|
import type { SWRConfiguration } from "swr";
|
||||||
import type { AxiosRequestConfig } from "axios";
|
import type { AxiosRequestConfig } from "axios";
|
||||||
import { get, post, patch, deleteOp } from "@/Utils/ApiClient";
|
import { get } from "@/Utils/ApiClient";
|
||||||
|
|
||||||
interface ApiResponse<T> {
|
interface ApiResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@@ -9,15 +9,8 @@ interface ApiResponse<T> {
|
|||||||
data: T;
|
data: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UseGetReturn<T> {
|
|
||||||
data: T | undefined;
|
|
||||||
isLoading: boolean;
|
|
||||||
error: Error | undefined;
|
|
||||||
refetch: () => Promise<ApiResponse<T> | undefined>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetcher = async <T>(url: string, config?: AxiosRequestConfig) => {
|
const fetcher = async <T>(url: string, config?: AxiosRequestConfig) => {
|
||||||
const res = await get<T>(url, config);
|
const res = await get<ApiResponse<T>>(url, config);
|
||||||
return res.data;
|
return res.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +18,7 @@ export const useGet = <T>(
|
|||||||
url: string | null,
|
url: string | null,
|
||||||
axiosConfig?: AxiosRequestConfig,
|
axiosConfig?: AxiosRequestConfig,
|
||||||
swrConfig?: SWRConfiguration
|
swrConfig?: SWRConfiguration
|
||||||
): UseGetReturn<T> => {
|
) => {
|
||||||
const { data, error, isLoading, mutate } = useSWR<ApiResponse<T>>(
|
const { data, error, isLoading, mutate } = useSWR<ApiResponse<T>>(
|
||||||
url,
|
url,
|
||||||
(url: string) => fetcher<T>(url, axiosConfig),
|
(url: string) => fetcher<T>(url, axiosConfig),
|
||||||
@@ -33,7 +26,7 @@ export const useGet = <T>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: data?.data,
|
data: data?.data ?? null,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
refetch: mutate,
|
refetch: mutate,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { Check } from "@/Types/Check";
|
import type { Check } from "@/Types/Check";
|
||||||
export type MonitorStatus = "up" | "down" | "initializing";
|
export type MonitorStatus = "up" | "down" | "initializing";
|
||||||
|
|
||||||
export interface IMonitor {
|
export interface Monitor {
|
||||||
checks: Check[];
|
checks: Check[];
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
|
|||||||
Reference in new issue
Block a user