1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-09 11:14:29 +02:00

feat: add placeholder getter hook

This commit is contained in:
Thomas Heartman 2024-10-31 13:16:37 +01:00
parent 3cd9e48dbb
commit d087f8a32d
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78

View File

@ -0,0 +1,43 @@
import useSWR from 'swr';
import { useMemo } from 'react';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import type { IUser } from 'interfaces/user';
import type { IRole } from 'interfaces/role';
import type { ActionableChangeRequestsSchema } from 'openapi/models/actionableChangeRequestsSchema';
interface IUseUsersOutput {
users: IUser[];
roles: IRole[];
loading: boolean;
refetch: () => void;
error?: Error;
}
export const useActionableChangeRequests = (
projectId: string,
): IUseUsersOutput => {
const { data, error, mutate } = useSWR<ActionableChangeRequestsSchema>(
formatApiPath(
`api/admin/projects/${projectId}/change-requests/actionable`,
),
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());
};