import React, { useState, useEffect } from "react"; import { organizationListCall, organizationMemberAddCall, Member, modelAvailableCall } from "./networking"; import { Col, Grid, Text } from "@tremor/react"; import OrganizationForm from "@/components/organization/add_org"; import AddOrgAdmin from "@/components/organization/add_org_admin"; import MemberListTable from "@/components/organization/view_members_of_org"; import { Select, SelectItem } from "@tremor/react"; const isLocal = process.env.NODE_ENV === "development"; const proxyBaseUrl = isLocal ? "http://localhost:4000" : null; if (isLocal != true) { console.log = function() {}; } interface TeamProps { teams: any[] | null; searchParams: any; accessToken: string | null; setTeams: React.Dispatch>; userID: string | null; userRole: string | null; premiumUser: boolean; } import DataTable from "@/components/common_components/all_view"; import { Action } from "@/components/common_components/all_view"; import { Typography, message } from "antd"; import { Organization, EditModalProps } from "@/components/organization/types"; interface OrganizationsTableProps { organizations: Organization[]; userRole?: string; onEdit?: (organization: Organization) => void; onDelete?: (organization: Organization) => void; isDeleteModalOpen: boolean; setIsDeleteModalOpen: (value: boolean) => void; selectedOrganization: Organization | null; setSelectedOrganization: (value: Organization | null) => void; } const EditOrganizationModal: React.FC = ({ visible, onCancel, entity, onSubmit }) => { return
; }; // Inside your Teams component const OrganizationsTable: React.FC = ({ organizations, userRole, onEdit, onDelete, isDeleteModalOpen, setIsDeleteModalOpen, selectedOrganization, setSelectedOrganization }) => { const columns = [ { header: "Organization Name", accessor: "organization_alias", width: "4px", style: { whiteSpace: "pre-wrap", overflow: "hidden" } }, { header: "Organization ID", accessor: "organization_id", width: "4px", style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", fontSize: "0.75em" } }, { header: "Spend (USD)", accessor: "spend" }, { header: "Budget (USD)", accessor: "max_budget", cellRenderer: (value: number | null) => value !== null && value !== undefined ? value : "No limit" }, { header: "Models", accessor: "models" }, { header: "TPM / RPM Limits", accessor: "limits", cellRenderer: (value: any, row: Organization) => (
TPM: {row.tpm_limit ? row.tpm_limit : "Unlimited"}
RPM: {row.rpm_limit ? row.rpm_limit : "Unlimited"}
) }, { header: "Info", accessor: "info", cellRenderer: (value: any, row: Organization) => (
{row.members?.length || 0} Members
) } ]; const actions: Action[] = [ ...(onEdit && userRole === "Admin" ? [{ icon: undefined, // Replace with your PencilAltIcon onClick: (org: Organization) => onEdit(org), condition: () => userRole === "Admin", tooltip: "Edit organization" }] : []), ...(onDelete && userRole === "Admin" ? [{ icon: undefined, // Replace with your TrashIcon onClick: (org: Organization) => onDelete(org), condition: () => userRole === "Admin", tooltip: "Delete organization" }] : []) ]; return ( { if (selectedOrganization && onDelete) { onDelete(selectedOrganization); } setIsDeleteModalOpen(false); setSelectedOrganization(null); }, onCancel: () => { setIsDeleteModalOpen(false); setSelectedOrganization(null); }, title: "Delete Organization", message: "Are you sure you want to delete this organization?" }} /> ); }; const Organizations: React.FC = ({ accessToken, userID, userRole, premiumUser }) => { const [organizations, setOrganizations] = useState([]); const { Title, Paragraph } = Typography; const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedOrganization, setSelectedOrganization] = useState(null); const [userModels, setUserModels] = useState([]); useEffect(() => { if (!accessToken || !userID || !userRole) return; const fetchUserModels = async () => { try { const model_available = await modelAvailableCall( accessToken, userID, userRole ); let available_model_names = model_available["data"].map( (element: { id: string }) => element.id ); console.log("available_model_names:", available_model_names); setUserModels(available_model_names); } catch (error) { console.error("Error fetching user models:", error); } }; const fetchData = async () => { let givenOrganizations; givenOrganizations = await organizationListCall(accessToken) console.log(`givenOrganizations: ${givenOrganizations}`) setOrganizations(givenOrganizations) sessionStorage.setItem('organizations', JSON.stringify(givenOrganizations)); } if (premiumUser) { fetchUserModels() fetchData() } }, [accessToken]); const handleMemberCreate = async (formValues: Record) => { if (!selectedOrganization || !accessToken) return; try { let member: Member = { user_email: formValues.user_email, user_id: formValues.user_id, role: formValues.role } await organizationMemberAddCall( accessToken, selectedOrganization["organization_id"], member ); message.success("Member added"); } catch (error) { console.error("Error creating the team:", error); message.error("Error creating the organization: " + error); } }; return (
✨ All Organizations This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key here {userRole ? OrganizationsTable({organizations, userRole, isDeleteModalOpen, setIsDeleteModalOpen, selectedOrganization, setSelectedOrganization}) : null} {userRole == "Admin" && accessToken && premiumUser ? : null} {premiumUser ? Organization Members If you belong to multiple organizations, this setting controls which organizations' members you see. {organizations && organizations.length > 0 ? ( ) : ( No team created. Defaulting to personal account. )} : null} {userRole == "Admin" && userID && selectedOrganization && premiumUser ? : null} {userRole == "Admin" && userID && selectedOrganization && premiumUser ? {}} editModalComponent={EditOrganizationModal} entityType="organization" /> : null}
); }; export default Organizations;