fix: resolve all admin typecheck errors (typed api wrapper, unused imports, missing hooks, PermissionButton children)

This commit is contained in:
2026-07-06 01:02:26 +08:00
parent 4a48a65a48
commit 6b0a21d266
22 changed files with 4051 additions and 273 deletions

View File

@@ -1,11 +1,11 @@
import axios from 'axios';
import axios, { type AxiosRequestConfig } from 'axios';
const api = axios.create({
const instance = axios.create({
baseURL: '/api',
timeout: 10000,
});
api.interceptors.request.use((config) => {
instance.interceptors.request.use((config) => {
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
@@ -17,7 +17,7 @@ api.interceptors.request.use((config) => {
return config;
});
api.interceptors.response.use(
instance.interceptors.response.use(
(res) => res.data,
(err) => {
if (err.response?.status === 401) {
@@ -34,4 +34,24 @@ api.interceptors.response.use(
},
);
const request = <T>(
method: string,
url: string,
data?: unknown,
config?: AxiosRequestConfig,
): Promise<T> => instance.request({ ...config, method, url, data }) as Promise<T>;
const api = {
get: <T>(url: string, config?: AxiosRequestConfig): Promise<T> =>
request<T>('get', url, undefined, config),
post: <T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T> =>
request<T>('post', url, data, config),
put: <T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T> =>
request<T>('put', url, data, config),
patch: <T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T> =>
request<T>('patch', url, data, config),
delete: <T>(url: string, config?: AxiosRequestConfig): Promise<T> =>
request<T>('delete', url, undefined, config),
};
export default api;