import React, { useState, useEffect } from "react"; import { Card, Title, Subtitle, Table, TableHead, TableRow, TableCell, TableBody, Tab, TabGroup, TabList, Metric, Grid, } from "@tremor/react"; import { userInfoCall } from "./networking"; import { Badge, BadgeDelta, Button } from "@tremor/react"; import RequestAccess from "./request_model_access"; import CreateUser from "./create_user_button"; interface ViewUserDashboardProps { accessToken: string | null; token: string | null; userRole: string | null; userID: string | null; } const ViewUserDashboard: React.FC = ({ accessToken, token, userRole, userID, }) => { const [userData, setUserData] = useState(null); const [currentPage, setCurrentPage] = useState(1); const defaultPageSize = 25; useEffect(() => { if (!accessToken || !token || !userRole || !userID) { return; } const fetchData = async () => { try { // Replace with your actual API call for model data const userDataResponse = await userInfoCall( accessToken, null, userRole, true ); console.log("user data response:", userDataResponse); setUserData(userDataResponse); } catch (error) { console.error("There was an error fetching the model data", error); } }; if (accessToken && token && userRole && userID) { fetchData(); } }, [accessToken, token, userRole, userID]); if (!userData) { return
Loading...
; } if (!accessToken || !token || !userRole || !userID) { return
Loading...
; } function renderPagination() { if (!userData) return null; const totalPages = Math.ceil(userData.length / defaultPageSize); const startItem = (currentPage - 1) * defaultPageSize + 1; const endItem = Math.min(currentPage * defaultPageSize, userData.length); return (
Showing {startItem} – {endItem} of {userData.length}
); } return (
Key Owners End-Users User ID User Role User Models User Spend ($ USD) User Max Budget ($ USD) {userData.map((user: any) => ( {user.user_id} {user.user_role ? user.user_role : "app_owner"} {user.models && user.models.length > 0 ? user.models : "All Models"} {user.spend ? user.spend : 0} {user.max_budget ? user.max_budget : "Unlimited"} ))}
{renderPagination()}
); }; export default ViewUserDashboard;