import { ContextModalProps } from "@mantine/modals"; import { Fieldset, Textarea, TextInput } from "@mantine/core"; import { useForm } from "@mantine/form"; import { ClientSchema } from "../../../../client"; import BaseFormModal, { CreateEditFormProps, } from "../BaseFormModal/BaseFormModal.tsx"; import BarcodeTemplateSelect from "../../../../components/Selects/BarcodeTemplateSelect/BarcodeTemplateSelect.tsx"; type Props = CreateEditFormProps; const ClientFormModal = ({ context, id, innerProps, }: ContextModalProps) => { const isEditing = "onChange" in innerProps; const initialValues: ClientSchema = isEditing ? innerProps.element : { id: -1, name: "", companyName: "", details: { telegram: "", phoneNumber: "", email: "", inn: undefined, }, comment: "", }; const form = useForm({ initialValues: initialValues, validate: { name: (name: string) => name.trim() !== "" ? null : "Необходимо ввести название клиента", // details: { // telegram: (address: string | undefined | null) => (address && address.trim() !== '') ? null : "Необходимо ввести телеграм", // phoneNumber: (phoneNumber: string | undefined | null) => (phoneNumber && phoneNumber.trim() !== '') ? null : "Необходимо ввести номер телефона", // email: (email: string | undefined | null) => (email && email.trim() !== '') ? null : "Необходимо ввести почту", // inn: (inn: string | undefined | null) => (inn && getDigitsCount(parseInt(inn)) >= 10) ? null : "ИНН должен содержать не менее 10 цифр", // } }, }); const onClose = () => { context.closeContextModal(id); }; return ( <>