import React from "react"; import { Form, Input, InputNumber, Row, Col, Button as Button2 } from "antd"; import { TrashIcon, CheckCircleIcon } from "@heroicons/react/outline"; import { Button, Badge, Icon, Text, TableRow, TableCell } from "@tremor/react"; import Paragraph from "antd/es/typography/Paragraph"; interface AlertingSetting { field_name: string; field_description: string; field_type: string; field_value: any; stored_in_db: boolean | null; premium_field: boolean; } interface DynamicFormProps { alertingSettings: AlertingSetting[]; handleInputChange: (fieldName: string, newValue: any) => void; handleResetField: (fieldName: string, index: number) => void; handleSubmit: (formValues: Record) => void; premiumUser: boolean; } const DynamicForm: React.FC = ({ alertingSettings, handleInputChange, handleResetField, handleSubmit, premiumUser, }) => { const [form] = Form.useForm(); const onFinish = () => { const formData = form.getFieldsValue(); const isEmpty = Object.values(formData).some( (value) => value === "" || value === null || value === undefined ); if (!isEmpty) { handleSubmit(formData); } else { console.log("Some form fields are empty."); } }; return (
{alertingSettings.map((value, index) => ( {value.field_name}

{value.field_description}

{value.premium_field ? ( premiumUser ? ( {value.field_type === "Integer" ? ( handleInputChange(value.field_name, e)} /> ) : ( handleInputChange(value.field_name, e)} /> )} ) : ( ) ) : ( {value.field_type === "Integer" ? ( handleInputChange(value.field_name, e)} className="p-0" /> ) : ( handleInputChange(value.field_name, e)} /> )} )} {value.stored_in_db == true ? ( In DB ) : value.stored_in_db == false ? ( In Config ) : ( Not Set )} handleResetField(value.field_name, index)} > Reset
))}
Update Settings
); }; export default DynamicForm;