2020-08-21 04:44:33 +00:00
|
|
|
import useSWR from 'swr';
|
|
|
|
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
|
|
|
import { ServerBackup } from '@/api/server/types';
|
2020-08-22 22:46:13 +00:00
|
|
|
import { rawDataToServerBackup } from '@/api/transformers';
|
2020-08-26 04:39:00 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
2020-08-21 04:44:33 +00:00
|
|
|
|
|
|
|
export default (page?: number | string) => {
|
2020-08-26 04:39:00 +00:00
|
|
|
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
2020-08-21 04:44:33 +00:00
|
|
|
|
|
|
|
return useSWR<PaginatedResult<ServerBackup>>([ 'server:backups', uuid, page ], async () => {
|
|
|
|
const { data } = await http.get(`/api/client/servers/${uuid}/backups`, { params: { page } });
|
|
|
|
|
|
|
|
return ({
|
|
|
|
items: (data.data || []).map(rawDataToServerBackup),
|
|
|
|
pagination: getPaginationSet(data.meta.pagination),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|