mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Network alerts
This commit is contained in:
@@ -1,20 +1,49 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import axios from "axios";
|
||||
import { Network } from "@/app/types";
|
||||
|
||||
const useNetworks = () => {
|
||||
|
||||
const addNetwork = (network: Network) => {
|
||||
axios.post('/api/sites/networks/add', network);
|
||||
if (!network.name) {
|
||||
return 'Network name is required';
|
||||
}
|
||||
axios.post('/api/sites/networks/add', network)
|
||||
.then(() => {
|
||||
return;
|
||||
})
|
||||
.catch(err => {
|
||||
return err.response?.data?.error || 'An error occurred';
|
||||
});
|
||||
};
|
||||
|
||||
const editNetwork = (network: Network) => {
|
||||
axios.post('/api/sites/networks/edit', network);
|
||||
if (!network.id) {
|
||||
return 'Network ID is required';
|
||||
}
|
||||
if(network.name.length < 1) {
|
||||
return 'Network name must be at least 1 character long';
|
||||
}
|
||||
axios.post('/api/sites/networks/edit', network)
|
||||
.then(() => {
|
||||
return;
|
||||
})
|
||||
.catch(err => {
|
||||
return err.response?.data?.error || 'An error occurred';
|
||||
});
|
||||
};
|
||||
|
||||
const deleteNetwork = (networkId: string) => {
|
||||
if (!networkId) {
|
||||
return 'Network ID is required';
|
||||
}
|
||||
axios.delete('/api/sites/networks/delete', {
|
||||
params: { networkId }
|
||||
})
|
||||
.then(() => {
|
||||
return;
|
||||
})
|
||||
.catch(err => {
|
||||
return err.response?.data?.error || 'An error occurred';
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user