Add admin UI
Some checks failed
CI / Test (pull_request) Failing after 1m33s
CI / Lint (pull_request) Failing after 13s
CI / Build (pull_request) Has been skipped
CI / Security Scan (pull_request) Failing after 4m47s
CI / Build and Push Docker Image (pull_request) Has been skipped

This commit is contained in:
2026-03-05 23:08:34 +00:00
parent 667217e66b
commit 7025ec746c
31 changed files with 5905 additions and 3 deletions

View File

@@ -0,0 +1,51 @@
import axios, { AxiosInstance } from 'axios'
import type { APIResponse } from '../types/api'
class APIClient {
private client: AxiosInstance
constructor() {
this.client = axios.create({
baseURL: '/admin/api/v1',
headers: {
'Content-Type': 'application/json',
},
})
// Request interceptor for auth
this.client.interceptors.request.use((config) => {
const token = localStorage.getItem('auth_token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
// Response interceptor for error handling
this.client.interceptors.response.use(
(response) => response,
(error) => {
console.error('API Error:', error)
return Promise.reject(error)
}
)
}
async get<T>(url: string): Promise<T> {
const response = await this.client.get<APIResponse<T>>(url)
if (response.data.success && response.data.data) {
return response.data.data
}
throw new Error(response.data.error?.message || 'Unknown error')
}
async post<T>(url: string, data: any): Promise<T> {
const response = await this.client.post<APIResponse<T>>(url, data)
if (response.data.success && response.data.data) {
return response.data.data
}
throw new Error(response.data.error?.message || 'Unknown error')
}
}
export const apiClient = new APIClient()