import BaseFormModal, {CreateEditFormProps} from "../../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx"; import { BarcodeTemplateAdditionalAttributeSchema, BarcodeTemplateAttributeSchema, BarcodeTemplateSchema } from "../../../../client"; import {ContextModalProps} from "@mantine/modals"; import {useForm} from "@mantine/form"; import {Checkbox, Fieldset, Flex, NumberInput, rem, TextInput} from "@mantine/core"; import {IconX} from "@tabler/icons-react"; import BarcodeTemplateAttributeMultiselect from "../../components/BarcodeTemplateAttributeMultiselect/BarcodeTemplateAttributeMultiselect.tsx"; import BarcodeTemplateAdditionalFieldTable from "../../components/BarcodeTemplateAdditionalFieldTable/BarcodeTemplateAdditionalFieldTable.tsx"; type Props = CreateEditFormProps const BarcodeTemplateFormModal = ({ context, id, innerProps }: ContextModalProps) => { const isEditing = 'onChange' in innerProps; const initialValues = isEditing ? innerProps.element : { name: "", width: undefined, height: undefined, isDefault: false, attributes: [] as Array, additionalAttributes: [] as Array } as Partial; const form = useForm>({ initialValues: initialValues, validate: { width: (width: number | undefined) => width && width > 0 ? null : "Ширина должна быть больше 0", height: (height: number | undefined) => height && height > 0 ? null : "Высота должна быть больше 0", attributes: (attributes: Array | undefined) => attributes && attributes.length > 0 ? null : "Необходимо добавить хотя бы один атрибут", name: (name: string | undefined) => name && name.trim() !== '' ? null : "Необходимо ввести название шаблона", } }) console.log(form.values.additionalAttributes); return ( context.closeContextModal(id)} > <>
) } export default BarcodeTemplateFormModal;