'use client'; import formatPhone from '@/shared/lib/formatPhone'; import { Button } from '@/shared/ui/button'; import { Card } from '@/shared/ui/card'; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@/shared/ui/form'; import { Input } from '@/shared/ui/input'; import { Label } from '@/shared/ui/label'; import { zodResolver } from '@hookform/resolvers/zod'; import { Upload } from 'lucide-react'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { toast } from 'sonner'; import * as z from 'zod'; const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB const ACCEPTED_FILE_TYPES = [ 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', ]; const partnershipFormSchema = z.object({ companyName: z.string().min(2, { message: "Kompaniya nomi kamida 2 ta belgidan iborat bo'lishi kerak", }), website: z .string() .url({ message: "To'g'ri website manzilini kiriting" }) .optional() .or(z.literal('')), contactPerson: z .string() .min(2, { message: "Ism kamida 2 ta belgidan iborat bo'lishi kerak" }), email: z .string() .email({ message: "To'g'ri email manzilini kiriting" }) .optional(), phone: z .string() .min(9, { message: "To'g'ri telefon raqamini kiriting" }) .regex(/^[\d\s+\-$$$$]+$/, { message: "Telefon raqami faqat raqamlardan iborat bo'lishi kerak", }), companyFile: z .custom() .refine((files) => files?.length === 1, 'File yuklash majburiy') .refine( (files) => files?.[0]?.size <= MAX_FILE_SIZE, 'File hajmi 5MB dan oshmasligi kerak', ) .refine( (files) => ACCEPTED_FILE_TYPES.includes(files?.[0]?.type), 'Faqat PDF yoki Word formatidagi fayllar qabul qilinadi', ), }); type PartnershipFormValues = z.infer; export function PartnershipForm() { const [isSubmitting, setIsSubmitting] = useState(false); const form = useForm({ resolver: zodResolver(partnershipFormSchema), defaultValues: { companyName: '', website: '', contactPerson: '', email: '', phone: '+998', }, }); async function onSubmit(data: PartnershipFormValues) { console.log(data); setIsSubmitting(true); try { await new Promise((resolve) => setTimeout(resolve, 2000)); toast.success("So'rov yuborildi!", { richColors: true, position: 'top-center', }); form.reset(); } catch { toast.error('Xatolik yuz berdi', { richColors: true, position: 'top-center', }); } finally { setIsSubmitting(false); } } return (

{`Hamkor bo'ling`}

{`Gastro Market bilan hamkorlik qilishni xohlaysizmi? Quyidagi formani to'ldiring va biz siz bilan tez orada bog'lanamiz.`}

( )} /> ( )} /> ( )} />
( )} /> ( )} />
(
{ const files = e.target.files; onChange(files); }} {...field} className="hidden" />

Faylni tanlang

{value && value.length > 0 && (

Tanlangan fayl: {value[0].name}

)}
PDF yoki Word formatida (maksimal 5MB)
)} />
); }