1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00
unleash.unleash/frontend/src/hooks/api/getters/useUsers/useUsers.ts
Fredrik Strand Oseberg 85a7c55fdf Feat/group by projects (#308)
This PR adds support for projects as a first class citizen, and toggling features on in different environments.
2021-07-07 11:04:36 +02:00

34 lines
820 B
TypeScript

import useSWR, { mutate } from 'swr';
import { useState, useEffect } from 'react';
import { formatApiPath } from '../../../../utils/format-path';
const useUsers = () => {
const fetcher = () => {
const path = formatApiPath(`api/admin/user-admin`);
return fetch(path, {
method: 'GET',
}).then(res => res.json());
};
const { data, error } = useSWR(`api/admin/user-admin`, fetcher);
const [loading, setLoading] = useState(!error && !data);
const refetch = () => {
mutate(`api/admin/user-admin`);
};
useEffect(() => {
setLoading(!error && !data);
}, [data, error]);
return {
users: data?.users || [],
roles: data?.rootRoles || [],
error,
loading,
refetch,
};
};
export default useUsers;