Fix RolesContainer, refactor NestsContainer

This commit is contained in:
Matthew Penner 2021-01-03 16:25:32 -07:00
parent ce40194147
commit b1d30c1bde
8 changed files with 74 additions and 107 deletions

View file

@ -1,25 +0,0 @@
import { Nest } from '@/api/admin/nests/getNests';
import useSWR from 'swr';
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
import { rawDataToNest } from '@/api/transformers';
import { createContext, useContext } from 'react';
interface ctx {
page: number;
setPage: (value: number | ((s: number) => number)) => void;
}
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
export default () => {
const { page } = useContext(Context);
return useSWR<PaginatedResult<Nest>>([ 'nests', page ], async () => {
const { data } = await http.get(`/api/application/nests`, { params: { page } });
return ({
items: (data.data || []).map(rawDataToNest),
pagination: getPaginationSet(data.meta.pagination),
});
});
};