import React, { useState, useEffect } from "react"; import Link from "next/link"; import { Typography } from "antd"; import { Button as Button2, Modal, Form, Input, Select as Select2, InputNumber, message, } from "antd"; import { Select, SelectItem } from "@tremor/react"; import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow, Card, Icon, Button, Col, Text, Grid, } from "@tremor/react"; import { CogIcon } from "@heroicons/react/outline"; interface TeamProps { teams: any[] | null; searchParams: any; accessToken: string | null; setTeams: React.Dispatch>; } import { teamCreateCall, teamMemberAddCall, Member } from "./networking"; const Team: React.FC = ({ teams, searchParams, accessToken, setTeams, }) => { const [form] = Form.useForm(); const [memberForm] = Form.useForm(); const { Title, Paragraph } = Typography; const [value, setValue] = useState(""); const [selectedTeam, setSelectedTeam] = useState( teams ? teams[0] : null ); const [isTeamModalVisible, setIsTeamModalVisible] = useState(false); const [isAddMemberModalVisible, setIsAddMemberModalVisible] = useState(false); const handleOk = () => { setIsTeamModalVisible(false); form.resetFields(); }; const handleMemberOk = () => { setIsAddMemberModalVisible(false); memberForm.resetFields(); }; const handleCancel = () => { setIsTeamModalVisible(false); form.resetFields(); }; const handleMemberCancel = () => { setIsAddMemberModalVisible(false); memberForm.resetFields(); }; const handleCreate = async (formValues: Record) => { try { if (accessToken != null) { message.info("Making API Call"); const response: any = await teamCreateCall(accessToken, formValues); if (teams !== null) { setTeams([...teams, response]); } else { setTeams([response]); } console.log(`response for team create call: ${response}`); setIsTeamModalVisible(false); } } catch (error) { console.error("Error creating the key:", error); } }; const handleMemberCreate = async (formValues: Record) => { try { if (accessToken != null && teams != null) { message.info("Making API Call"); const user_role: Member = { role: "user", user_email: formValues.user_email, user_id: null, }; const response: any = await teamMemberAddCall( accessToken, selectedTeam["team_id"], user_role ); console.log(`response for team create call: ${response["data"]}`); // Checking if the team exists in the list and updating or adding accordingly const foundIndex = teams.findIndex((team) => { console.log( `team.team_id=${team.team_id}; response.data.team_id=${response.data.team_id}` ); return team.team_id === response.data.team_id; }); console.log(`foundIndex: ${foundIndex}`); if (foundIndex !== -1) { // If the team is found, update it const updatedTeams = [...teams]; // Copy the current state updatedTeams[foundIndex] = response.data; // Update the specific team setTeams(updatedTeams); // Set the new state setSelectedTeam(response.data); } setIsAddMemberModalVisible(false); } } catch (error) { console.error("Error creating the key:", error); } }; console.log(`received teams ${teams}`); return (
All Teams Team Name Spend (USD) Budget (USD) TPM / RPM Limits {teams && teams.length > 0 ? teams.map((team: any) => ( {team["team_alias"]} {team["spend"]} {team["max_budget"] ? team["max_budget"] : "No limit"} TPM Limit:{" "} {team.tpm_limit ? team.tpm_limit : "Unlimited"}{" "}

RPM Limit:{" "} {team.rpm_limit ? team.rpm_limit : "Unlimited"}
)) : null}
<> {/* {userModels.map((model) => ( ))} */}
Create Team
Team Members If you belong to multiple teams, this setting controls which teams' members you see. {teams && teams.length > 0 ? ( ) : ( No team created. Defaulting to personal account. )} Member Name Role Action {selectedTeam ? selectedTeam["members_with_roles"].map((member: any) => ( {member["user_email"] ? member["user_email"] : member["user_id"] ? member["user_id"] : null} {member["role"]} )) : null}
<>
Add member
); }; export default Team;