import { DeleteOutlined } from '@ant-design/icons' import { Alert, Button, Checkbox, Form, Mentions, Popconfirm, Select } from 'antd' import { FormInstance } from 'antd/lib/form' import { FieldData } from 'rc-field-form/lib/interface' import React from 'react' import { useTranslation } from 'react-i18next' import { FormFieldFragment } from '../../../graphql/fragment/form.fragment' import { useMath } from '../../use.math' interface Props { form: FormInstance fields: FormFieldFragment[] field: FieldData remove: (index: number) => void index: number } export const LogicBlock: React.FC = ({ form, field, fields, remove, index, }) => { const { t } = useTranslation() const evaluator = useMath() return (
{fields.map((field) => ( {field.title} ))} {(form: FormInstance & { prefixName: string[] }) => { try { const defaults = {} fields.forEach((field) => { defaults[`@${field.id}`] = field.defaultValue if (field.slug) { defaults[`$${field.slug}`] = field.defaultValue } }) const result = evaluator( form.getFieldValue([ ...form.prefixName, field.name as string, 'formula', ]), defaults ) return ( ) } catch (e) { return ( ) } }} !/NEW/i.test(field.id)) .map((field) => ({ value: field.id, label: field.title, }))} /> ) }} {(form: FormInstance & { prefixName: string[] }) => { return ( ) }} {(form: FormInstance & { prefixName: string[] }) => { return ( ) }} {(form: FormInstance & { prefixName: string[] }) => { return ( ) }}
{ remove(index) }} >
) }