import { Button as Button2, Modal, Form, Select as Select2, InputNumber, message, } from "antd"; import { TextInput, Button, } from "@tremor/react"; import { organizationCreateCall } from "../networking"; // types.ts export interface FormData { name: string; models: string[]; maxBudget: number | null; budgetDuration: string | null; tpmLimit: number | null; rpmLimit: number | null; } export interface OrganizationFormProps { title?: string; onCancel?: () => void; accessToken: string | null; availableModels?: string[]; initialValues?: Partial; submitButtonText?: string; modelSelectionType?: 'single' | 'multiple'; } // OrganizationForm.tsx import React, { useState } from 'react'; const onSubmit = async (formValues: Record, accessToken: string | null, setIsModalVisible: any) => { if (accessToken == null) { return; } try { message.info("Creating Organization"); console.log("formValues: " + JSON.stringify(formValues)); const response: any = await organizationCreateCall(accessToken, formValues); console.log(`response for organization create call: ${response}`); message.success("Organization created"); sessionStorage.removeItem('organizations'); setIsModalVisible(false); } catch (error) { console.error("Error creating the organization:", error); message.error("Error creating the organization: " + error, 20); } } const OrganizationForm: React.FC = ({ title = "Create Organization", onCancel, accessToken, availableModels = [], initialValues = {}, submitButtonText = "Create", modelSelectionType = "multiple", }) => { const [form] = Form.useForm(); const [isModalVisible, setIsModalVisible] = useState(false); const [formData, setFormData] = useState({ name: initialValues.name || '', models: initialValues.models || [], maxBudget: initialValues.maxBudget || null, budgetDuration: initialValues.budgetDuration || null, tpmLimit: initialValues.tpmLimit || null, rpmLimit: initialValues.rpmLimit || null }); console.log(`availableModels: ${availableModels}`) const handleSubmit = async (formValues: Record) => { if (accessToken == null) { return; } await onSubmit(formValues, accessToken, setIsModalVisible); setIsModalVisible(false); }; const handleCancel = (): void => { setIsModalVisible(false); if (onCancel) onCancel(); }; return (
<> All Proxy Models {availableModels.map((model) => ( {model} ))} daily weekly monthly
{submitButtonText}
); }; export default OrganizationForm;