2020-11-01 04:22:44 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import useSWR from 'swr';
|
|
|
|
import http from '@/api/http';
|
2022-02-27 17:25:31 +00:00
|
|
|
import { Allocation, Transformers } from '@definitions/user';
|
2020-11-01 04:22:44 +00:00
|
|
|
|
2020-11-01 05:30:03 +00:00
|
|
|
export default () => {
|
2020-11-01 04:22:44 +00:00
|
|
|
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
|
|
|
|
|
|
|
return useSWR<Allocation[]>([ 'server:allocations', uuid ], async () => {
|
|
|
|
const { data } = await http.get(`/api/client/servers/${uuid}/network/allocations`);
|
|
|
|
|
2022-02-27 17:25:31 +00:00
|
|
|
return (data.data || []).map(Transformers.toServerAllocation);
|
2020-11-01 05:30:03 +00:00
|
|
|
}, { revalidateOnFocus: false, revalidateOnMount: false });
|
2020-11-01 04:22:44 +00:00
|
|
|
};
|