mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
570e9f88be
* feat: upgrade users table * fix misc ui/ux bugs * refactor: address PR comments * fix: searching by `undefined` * fix: searching for undefined on invoices, table placeholder centering * refactor: abstract users list actions into new component * refactor: move styled components to top of files
29 lines
726 B
TypeScript
29 lines
726 B
TypeScript
import useSWR from 'swr';
|
|
import { useMemo } from 'react';
|
|
import { formatApiPath } from 'utils/formatPath';
|
|
import handleErrorResponses from '../httpErrorResponseHandler';
|
|
|
|
export const useUsers = () => {
|
|
const { data, error, mutate } = useSWR(
|
|
formatApiPath(`api/admin/user-admin`),
|
|
fetcher
|
|
);
|
|
|
|
return useMemo(
|
|
() => ({
|
|
users: data?.users ?? [],
|
|
roles: data?.rootRoles ?? [],
|
|
loading: !error && !data,
|
|
refetch: () => mutate(),
|
|
error,
|
|
}),
|
|
[data, error, mutate]
|
|
);
|
|
};
|
|
|
|
const fetcher = (path: string) => {
|
|
return fetch(path)
|
|
.then(handleErrorResponses('Users'))
|
|
.then(res => res.json());
|
|
};
|