ServersContainer: cleanup api code
This commit is contained in:
parent
b4ec1fb45d
commit
e7021dfc39
|
@ -49,11 +49,11 @@ interface ctx {
|
||||||
|
|
||||||
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
|
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
|
||||||
|
|
||||||
export default () => {
|
export default (include: string[] = []) => {
|
||||||
const { page } = useContext(Context);
|
const { page } = useContext(Context);
|
||||||
|
|
||||||
return useSWR<PaginatedResult<Server>>([ 'servers', page ], async () => {
|
return useSWR<PaginatedResult<Server>>([ 'servers', page ], async () => {
|
||||||
const { data } = await http.get('/api/application/servers', { params: { include: 'node,user', page } });
|
const { data } = await http.get('/api/application/servers', { params: { include: include.join(','), page } });
|
||||||
|
|
||||||
return ({
|
return ({
|
||||||
items: (data.data || []).map(rawDataToServerObject),
|
items: (data.data || []).map(rawDataToServerObject),
|
||||||
|
|
|
@ -36,7 +36,7 @@ const UsersContainer = () => {
|
||||||
|
|
||||||
const { page, setPage } = useContext(ServersContext);
|
const { page, setPage } = useContext(ServersContext);
|
||||||
const { clearFlashes, clearAndAddHttpError } = useFlash();
|
const { clearFlashes, clearAndAddHttpError } = useFlash();
|
||||||
const { data: servers, error, isValidating } = getServers();
|
const { data: servers, error, isValidating } = getServers([ 'node', 'user' ]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
@ -122,7 +122,6 @@ const UsersContainer = () => {
|
||||||
{/* TODO: Have permission check for displaying user information. */}
|
{/* TODO: Have permission check for displaying user information. */}
|
||||||
<td css={tw`px-6 text-sm text-left whitespace-nowrap`}>
|
<td css={tw`px-6 text-sm text-left whitespace-nowrap`}>
|
||||||
<NavLink to={`/admin/users/${server.relations.user?.id}`} css={tw`text-primary-400 hover:text-primary-300`}>
|
<NavLink to={`/admin/users/${server.relations.user?.id}`} css={tw`text-primary-400 hover:text-primary-300`}>
|
||||||
|
|
||||||
<div css={tw`text-sm text-neutral-200`}>
|
<div css={tw`text-sm text-neutral-200`}>
|
||||||
{server.relations.user?.firstName} {server.relations.user?.lastName}
|
{server.relations.user?.firstName} {server.relations.user?.lastName}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue