mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
This PR adds support for projects as a first class citizen, and toggling features on in different environments.
34 lines
820 B
TypeScript
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;
|