Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(ui): migrate organization view to useOrganization hook

Ryan Crabbe6e9cbbaad3b5
diff --git a/ui/litellm-dashboard/src/components/organization/organization_view.tsx b/ui/litellm-dashboard/src/components/organization/organization_view.tsx
index 4bbcc9f43b0..128e99ae84a 100644
--- a/ui/litellm-dashboard/src/components/organization/organization_view.tsx
+++ b/ui/litellm-dashboard/src/components/organization/organization_view.tsx
@@ -1,4 +1,6 @@
import { useTeams } from "@/app/(dashboard)/hooks/teams/useTeams";
+import { organizationKeys, useOrganization } from "@/app/(dashboard)/hooks/organizations/useOrganizations";
+import { useQueryClient } from "@tanstack/react-query";
import { formatNumberWithCommas, copyToClipboard as utilCopyToClipboard } from "@/utils/dataUtils";
import { createTeamAliasMap } from "@/utils/teamUtils";
import { ArrowLeftIcon } from "@heroicons/react/outline";
@@ -14,7 +16,7 @@ import {
import { Button, Form, Input, Select, Tabs, Typography } from "antd";
import type { ColumnsType } from "antd/es/table";
import { CheckIcon, CopyIcon } from "lucide-react";
-import React, { useEffect, useMemo, useState } from "react";
+import React, { useMemo, useState } from "react";
import MemberTable from "../common_components/MemberTable";
import UserSearchModal from "../common_components/user_search_modal";
import MCPServerSelector from "../mcp_server_management/MCPServerSelector";
@@ -23,7 +25,6 @@ import NotificationsManager from "../molecules/notifications_manager";
import {
Member,
Organization,
- organizationInfoCall,
organizationMemberAddCall,
organizationMemberDeleteCall,
organizationMemberUpdateCall,
@@ -53,8 +54,8 @@ const OrganizationInfoView: React.FC<OrganizationInfoProps> = ({
userModels,
editOrg,
}) => {
- const [orgData, setOrgData] = useState<Organization | null>(null);
- const [loading, setLoading] = useState(true);
+ const queryClient = useQueryClient();
+ const { data: orgData, isLoading: loading } = useOrganization(organizationId);
const [form] = Form.useForm();
const [isEditing, setIsEditing] = useState(false);
const [isAddMemberModalVisible, setIsAddMemberModalVisible] = useState(false);
@@ -67,24 +68,6 @@ const OrganizationInfoView: React.FC<OrganizationInfoProps> = ({
const teamAliasMap = useMemo(() => createTeamAliasMap(teams), [teams]);
- const fetchOrgInfo = async () => {
- try {
- setLoading(true);
- if (!accessToken) return;
- const response = await organizationInfoCall(accessToken, organizationId);
- setOrgData(response);
- } catch (error) {
- NotificationsManager.fromBackend("Failed to load organization information");
- console.error("Error fetching organization info:", error);
- } finally {
- setLoading(false);
- }
- };
-
- useEffect(() => {
- fetchOrgInfo();
- }, [organizationId, accessToken]);
-
const handleMemberAdd = async (values: any) => {
try {
if (accessToken == null) {
@@ -101,7 +84,7 @@ const OrganizationInfoView: React.FC<OrganizationInfoProps> = ({
NotificationsManager.success("Organization member added successfully");
setIsAddMemberModalVisible(false);
form.resetFields();
- fetchOrgInfo();
+ queryClient.invalidateQueries({ queryKey: organizationKeys.all });
} catch (error) {
NotificationsManager.fromBackend("Failed to add organization member");
console.error("Error adding organization member:", error);
@@ -122,7 +105,7 @@ const OrganizationInfoView: React.FC<OrganizationInfoProps> = ({
NotificationsManager.success("Organization member updated successfully");
setIsEditMemberModalVisible(false);
form.resetFields();
- fetchOrgInfo();
+ queryClient.invalidateQueries({ queryKey: organizationKeys.all });
} catch (error) {
NotificationsManager.fromBackend("Failed to update organization member");
console.error("Error updating organization member:", error);
@@ -137,7 +120,7 @@ const OrganizationInfoView: React.FC<OrganizationInfoProps> = ({
NotificationsManager.success("Organization member deleted successfully");
setIsEditMemberModalVisible(false);
form.resetFields();
- fetchOrgInfo();
+ queryClient.invalidateQueries({ queryKey: organizationKeys.all });
} catch (error) {
NotificationsManager.fromBackend("Failed to delete organization member");
console.error("Error deleting organization member:", error);
@@ -187,7 +170,7 @@ const OrganizationInfoView: React.FC<OrganizationInfoProps> = ({
NotificationsManager.success("Organization settings updated successfully");
setIsEditing(false);
- fetchOrgInfo();
+ queryClient.invalidateQueries({ queryKey: organizationKeys.all });
} catch (error) {
NotificationsManager.fromBackend("Failed to update organization settings");
console.error("Error updating organization:", error);