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, Switch } 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 = () => { console.log(`INSIDE ONFINISH`) const formData = form.getFieldsValue(); const isEmpty = Object.entries(formData).every(([key, value]) => { if (typeof value === 'boolean') { return false; // Boolean values are never considered empty } return value === '' || value === null || value === undefined; }); console.log(`formData: ${JSON.stringify(formData)}, isEmpty: ${isEmpty}`) 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)} /> ) : value.field_type === "Boolean" ? ( handleInputChange(value.field_name, checked)} /> ) : ( handleInputChange(value.field_name, e)} /> )} ) : ( ) ) : ( {value.field_type === "Integer" ? ( handleInputChange(value.field_name, e)} className="p-0" /> ) : value.field_type === "Boolean" ? ( { handleInputChange(value.field_name, checked); form.setFieldsValue({ [value.field_name]: checked }); }} /> ) :( 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;