mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
useServers hook
This commit is contained in:
parent
9a797194a2
commit
9f708e5746
@ -1,4 +1,3 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import axios, { AxiosError } from "axios";
|
||||
|
||||
interface MonitoringSettings {
|
||||
|
||||
57
hooks/useServers.ts
Normal file
57
hooks/useServers.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import axios, { AxiosError } from "axios";
|
||||
|
||||
interface Server {
|
||||
id: number;
|
||||
networkId: number;
|
||||
name: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
ipv4Address?: string;
|
||||
osDetails?: string;
|
||||
cpuDetails?: string;
|
||||
gpuDetails?: string;
|
||||
memoryDetails?: string;
|
||||
storageDetails?: string;
|
||||
monitoring: boolean;
|
||||
monitoringUrl?: string;
|
||||
managementUrl?: string;
|
||||
applications?: any[];
|
||||
virtualMachines?: any[];
|
||||
}
|
||||
|
||||
interface AddServer {
|
||||
networkId: number;
|
||||
name: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
|
||||
const useServers = () => {
|
||||
const getAllServers = (): Promise<Server[]> | string => {
|
||||
return axios.get('/api/servers/get_all')
|
||||
.then((response) => {
|
||||
return response.data.servers;
|
||||
})
|
||||
.catch(err => {
|
||||
throw err.response?.data?.error || 'Failed to fetch servers';
|
||||
});
|
||||
};
|
||||
|
||||
const addServer = (server: AddServer): Promise<Server> | string => {
|
||||
return axios.post('/api/servers/add', server)
|
||||
.then((response) => {
|
||||
return response.data.server;
|
||||
})
|
||||
.catch(err => {
|
||||
throw err.response?.data?.error || 'Failed to add server';
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
getAllServers,
|
||||
addServer,
|
||||
};
|
||||
};
|
||||
|
||||
export default useServers;
|
||||
Loading…
x
Reference in New Issue
Block a user