fix: add phone-input
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import s from './styles.module.scss';
|
||||
import { Button, Input } from '@shared/ui';
|
||||
import { Button, Input, PhoneInput } from '@shared/ui';
|
||||
import { Controller, useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import toast from 'react-hot-toast';
|
||||
import { sendFormFn } from '@shared/api/api.service';
|
||||
import { isValidPhoneNumber } from 'libphonenumber-js/min';
|
||||
|
||||
const FormSchema = z.object({
|
||||
name: z.string().min(3),
|
||||
phone: z.string(),
|
||||
name: z
|
||||
.string()
|
||||
.min(3, { message: 'Поле должно содержать не менее 3-х букв' })
|
||||
.regex(/^[A-Za-zА-Яа-яЁё]+(?:[ '-][A-Za-zА-Яа-яЁё]+)*$/, {
|
||||
message: 'Поле содержит некорректные символы',
|
||||
}),
|
||||
phone: z.string().refine(isValidPhoneNumber, 'Некорректный номер телефона'),
|
||||
});
|
||||
type TForm = z.infer<typeof FormSchema>;
|
||||
|
||||
@@ -67,11 +73,11 @@ export default function OfferForm() {
|
||||
control={control}
|
||||
name={'phone'}
|
||||
render={({ field }) => (
|
||||
<Input
|
||||
<PhoneInput
|
||||
{...field}
|
||||
className={s.Unit}
|
||||
type='text'
|
||||
placeholder='+7 (999) 123 45 67'
|
||||
placeholder='+7 999 123-45-67'
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user