Files

20 lines
672 B
TypeScript
Raw Permalink Normal View History

2020-10-31 21:22:44 -07:00
import { ServerContext } from '@/state/server';
import useSWR from 'swr';
import http from '@/api/http';
import { rawDataToServerAllocation } from '@/api/transformers';
import { Allocation } from '@/api/server/getServer';
2020-10-31 22:30:03 -07:00
export default () => {
const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid);
2020-10-31 21:22:44 -07:00
return useSWR<Allocation[]>(
['server:allocations', uuid],
async () => {
const { data } = await http.get(`/api/client/servers/${uuid}/network/allocations`);
2020-10-31 21:22:44 -07:00
return (data.data || []).map(rawDataToServerAllocation);
},
{ revalidateOnFocus: false, revalidateOnMount: false }
);
2020-10-31 21:22:44 -07:00
};