import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; import { FormProvider, useForm } from 'react-hook-form'; import { HInput, HRadioButtons } from '@/shared/ui/FormComponents'; import { classNames } from '@/shared/lib/classNames/classNames'; import { Button, ButtonSize, ButtonTheme } from '@/shared/ui/Button'; import cls from './AllFieldForm.module.scss'; import { regexMap } from '@/shared/lib/utils/regexMap'; import { IRadioButtons, RadioButtonsTheme } from '@/shared/ui/FormComponents/fieldsUI/RadioButtons/RadioButtons'; import { HCheckbox } from '@/shared/ui/FormComponents/rhfFields/HCheckbox/HCheckbox'; import { HTextarea } from '@/shared/ui/FormComponents/rhfFields/HTextarea/HTextarea'; const AllFieldFormSchema = z.object({ textInput: z // .string() .min(1, { message: 'Заполните поле' }) .max(255), maskIInput: z // .string() // .min(1, { message: 'Заполните поле' }) .max(255) .regex(/^\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}$/, { message: 'Укажите верный формат телефона' }), maskIInputLatin: z // .string() // .min(1, { message: 'Заполните поле' }) .max(255), radioButton: z // .string() // .min(1, { message: 'Выберите значение' }) .max(255), radioButtonParam: z // .string() // .min(1, { message: 'Выберите значение' }) .max(255), textarea: z // .string() .min(1, { message: 'Заполните поле' }) .max(255), checkbox: z.string(), }); type AllFieldFormType = z.infer; interface AllFieldFormProps { className?: string; } const defaultValues = { textInput: '', maskIInput: '', maskIInputLatin: '', radioButton: '', radioButtonParam: '', checkbox: '', textarea: '', }; export const AllFieldForm = (props: AllFieldFormProps) => { const { className } = props; const regex = regexMap.onlyRuSymbols; const methods = useForm({ defaultValues, resolver: zodResolver(AllFieldFormSchema), }); const { handleSubmit } = methods; const submitHandler = async (data: AllFieldFormType) => { console.log('data: ', data); }; const radioData: IRadioButtons[] = [ { labelName: 'Раз в квартал', value: '0', }, { labelName: 'Раз в пол года', value: '1', }, { labelName: 'Раз в год', value: '2', }, ]; const radioDataParam: IRadioButtons[] = [ { labelName: 'Раз в квартал', value: '0', }, { labelName: 'Раз в пол года', value: '1', }, { labelName: 'Раз в год', value: '2', }, ]; return (
Текст чекбокс
); };