feat: Created useUserTeamIds hook.

Signed-off-by: Marley Powell <Marley.Powell@exclaimer.com>
This commit is contained in:
Marley Powell
2021-12-16 14:38:13 +00:00
parent 060a39e4d8
commit 562670a7cb
2 changed files with 42 additions and 0 deletions
+1
View File
@@ -20,3 +20,4 @@ export * from './useProjectRepoFromEntity';
export * from './usePullRequests';
export * from './useRepoBuilds';
export * from './useUserEmail';
export * from './useUserTeamIds';
@@ -0,0 +1,41 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { azureDevOpsApiRef } from '../api';
import { useApi } from '@backstage/core-plugin-api';
import { useAsync } from 'react-use';
export function useUserTeamIds(userId: string | undefined): {
teamIds?: string[];
loading: boolean;
error?: Error;
} {
const api = useApi(azureDevOpsApiRef);
const {
value: teamIds,
loading,
error,
} = useAsync(() => {
return userId ? api.getUserTeamIds(userId) : Promise.resolve(undefined);
}, [api]);
return {
teamIds,
loading,
error,
};
}