mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Add TeamRolePicker to CreateTeam and TeamSettings pages * Align tests to the changes * Change TeamRolePicker * Add useRoleOptions hook * Clean up * Requested changes by reviewers * Fixes * Fixes
21 lines
649 B
TypeScript
21 lines
649 B
TypeScript
import { useState } from 'react';
|
|
import useAsync from 'react-use/lib/useAsync';
|
|
|
|
import { contextSrv } from 'app/core/core';
|
|
import { AccessControlAction } from 'app/types';
|
|
|
|
import { fetchRoleOptions } from './api';
|
|
|
|
export const useRoleOptions = (organizationId: number) => {
|
|
const [orgId, setOrgId] = useState(organizationId);
|
|
|
|
const { value = [] } = useAsync(async () => {
|
|
if (contextSrv.licensedAccessControlEnabled() && contextSrv.hasPermission(AccessControlAction.ActionRolesList)) {
|
|
return fetchRoleOptions(orgId);
|
|
}
|
|
return Promise.resolve([]);
|
|
}, [orgId]);
|
|
|
|
return [{ roleOptions: value }, setOrgId] as const;
|
|
};
|