feat: create api service PAI
This commit is contained in:
@ -1,18 +1,32 @@
|
||||
import { getApiServices } from "@/api/admin/apiServices";
|
||||
import type { ApiService } from "@/types";
|
||||
import {
|
||||
getApiServices,
|
||||
postApiService,
|
||||
type CreateApiServiceRequest,
|
||||
} from "@/api/admin/apiServices";
|
||||
import type { ApiService, ApiServiceCredentials } from "@/types";
|
||||
import { create } from "zustand";
|
||||
|
||||
interface IAdminState {
|
||||
apiServices: ApiService[];
|
||||
loadingApiServices: boolean;
|
||||
|
||||
createdCredentials: ApiServiceCredentials | null;
|
||||
creatingApiService: boolean;
|
||||
|
||||
fetchApiServices: () => Promise<void>;
|
||||
createApiService: (req: CreateApiServiceRequest) => Promise<void>;
|
||||
resetCredentials: () => void;
|
||||
}
|
||||
|
||||
export const useAdmin = create<IAdminState>((set) => ({
|
||||
apiServices: [],
|
||||
loadingApiServices: false,
|
||||
|
||||
createdCredentials: null,
|
||||
creatingApiService: false,
|
||||
|
||||
resetCredentials: () => set({ createdCredentials: null }),
|
||||
|
||||
fetchApiServices: async () => {
|
||||
set({ loadingApiServices: true });
|
||||
|
||||
@ -25,4 +39,17 @@ export const useAdmin = create<IAdminState>((set) => ({
|
||||
set({ loadingApiServices: false });
|
||||
}
|
||||
},
|
||||
|
||||
createApiService: async (req: CreateApiServiceRequest) => {
|
||||
set({ creatingApiService: true });
|
||||
|
||||
try {
|
||||
const response = await postApiService(req);
|
||||
set({ createdCredentials: response.credentials });
|
||||
} catch (err) {
|
||||
console.log("ERR: Failed to fetch services:", err);
|
||||
} finally {
|
||||
set({ creatingApiService: false });
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user