diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.json index 493b2089c68..4678669c3e1 100644 --- a/ui/litellm-dashboard/eslint-suppressions.json +++ b/ui/litellm-dashboard/eslint-suppressions.json @@ -1685,9 +1685,6 @@ "src/components/key_team_helpers/key_list.tsx": { "local/filename-pascal-case": { "count": 1 - }, - "react-hooks/set-state-in-effect": { - "count": 1 } }, "src/components/key_team_helpers/transform_key_info.tsx": { diff --git a/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx b/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx index d8c331110c0..ad357f5925d 100644 --- a/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx +++ b/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx @@ -1,6 +1,4 @@ -import { Setter } from "@/types"; -import { useEffect, useState } from "react"; -import { keyListCall, Member, Organization } from "../networking"; +import { Member } from "../networking"; import type { ObjectPermission } from "../object_permission_types"; import type { ModelBudgetUsage, ModelMaxBudget } from "./ModelMaxBudgetEditor"; @@ -126,114 +124,3 @@ export interface KeyResponse { user_alias: string | null; }; } - -interface KeyListResponse { - keys: KeyResponse[]; - total_count: number; - current_page: number; - total_pages: number; -} - -interface UseKeyListProps { - selectedTeam?: Team; - currentOrg: Organization | null; - selectedKeyAlias: string | null; - accessToken: string; - createClicked: boolean; - expand?: string[]; -} - -interface PaginationData { - currentPage: number; - totalPages: number; - totalCount: number; -} - -interface UseKeyListReturn { - keys: KeyResponse[]; - isLoading: boolean; - error: Error | null; - pagination: PaginationData; - refresh: (params?: Record) => Promise; - setKeys: Setter; -} - -const useKeyList = ({ - selectedTeam, - currentOrg, - selectedKeyAlias, - accessToken, - createClicked, - expand = [], -}: UseKeyListProps): UseKeyListReturn => { - const [keyData, setKeyData] = useState({ - keys: [], - total_count: 0, - current_page: 1, - total_pages: 0, - }); - const [isLoading, setIsLoading] = useState(true); - const [error, setError] = useState(null); - - const fetchKeys = async (params: Record = {}): Promise => { - try { - if (!accessToken) { - return; - } - setIsLoading(true); - - const page = typeof params.page === "number" ? params.page : 1; - const pageSize = typeof params.pageSize === "number" ? params.pageSize : 100; - - const data = await keyListCall( - accessToken, - null, - null, - null, - null, - null, - page, - pageSize, - null, - null, - expand.join(","), - ); - setKeyData(data); - setError(null); - } catch (err) { - setError(err instanceof Error ? err : new Error("An error occurred")); - } finally { - setIsLoading(false); - } - }; - - useEffect(() => { - fetchKeys(); - }, [selectedTeam, currentOrg, accessToken, selectedKeyAlias, createClicked]); - - const setKeys = (newKeysOrUpdater: KeyResponse[] | ((prevKeys: KeyResponse[]) => KeyResponse[])) => { - setKeyData((prevData) => { - const newKeys = typeof newKeysOrUpdater === "function" ? newKeysOrUpdater(prevData.keys) : newKeysOrUpdater; - - return { - ...prevData, - keys: newKeys, - }; - }); - }; - - return { - keys: keyData.keys, - isLoading, - error, - pagination: { - currentPage: keyData.current_page, - totalPages: keyData.total_pages, - totalCount: keyData.total_count, - }, - refresh: fetchKeys, - setKeys, - }; -}; - -export default useKeyList;