1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-15 01:16:22 +02:00
unleash.unleash/frontend/src/hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests.ts
Nuno Góis 9accbcfa8b
Fix pro project role descriptions (#2612)
https://linear.app/unleash/issue/2-485/bug-pro-access-page-the-tooltip-on-the-roles-is-not-working

Fixes an issue where we would not show anything for project role
permissions since we're not serving that specific endpoint below
Enterprise level. This way we fallback to the access role descriptions,
which are also nice and informative:


![image](https://user-images.githubusercontent.com/14320932/205987327-def46ef2-4010-47dd-ba7d-5a264f0b547d.png)


PR also adds support for SWR options in ConditionalSWR and
EnterpriseSWR.
2022-12-07 10:22:42 +00:00

26 lines
785 B
TypeScript

import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import { IChangeRequest } from 'component/changeRequest/changeRequest.types';
import { useEnterpriseSWR } from '../useEnterpriseSWR/useEnterpriseSWR';
const fetcher = (path: string) => {
return fetch(path)
.then(handleErrorResponses('ChangeRequest'))
.then(res => res.json());
};
export const usePendingChangeRequests = (project: string) => {
const { data, error, mutate } = useEnterpriseSWR<IChangeRequest[]>(
[],
formatApiPath(`api/admin/projects/${project}/change-requests/pending`),
fetcher
);
return {
draft: data,
loading: !error && !data,
refetch: mutate,
error,
};
};