diff --git a/components/ContactForm.tsx b/components/ContactForm.tsx index ad8172d..934ecf7 100644 --- a/components/ContactForm.tsx +++ b/components/ContactForm.tsx @@ -12,6 +12,7 @@ export function ContactForm() { const { t } = useLanguage(); const productName = useProductStore((state) => state.productName); + const reset = useProductStore((state) => state.resetProductName); const [formData, setFormData] = useState({ name: "", @@ -26,15 +27,29 @@ export function ContactForm() { text: string; } | null>(null); + const phoneRegex = /^\+?\d*$/; // + majburiy + const handleChange = ( e: React.ChangeEvent< HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement > ) => { - setFormData((prev) => ({ - ...prev, - [e.target.name]: e.target.value, - })); + const { name, value } = e.target; + + if (name === "phone") { + // regexga mos kelmasa — state o‘zgarmaydi + if (!phoneRegex.test(value)) return; + + setFormData((prev) => ({ + ...prev, + phone: value, + })); + } else { + setFormData((prev) => ({ + ...prev, + [name]: value, + })); + } }; const handleSubmit = async (e: React.FormEvent) => { @@ -62,6 +77,8 @@ ${formData.message || "—"} text: text, }); setMessage({ type: "success", text: t.contact.success }); + reset(); + setFormData({ name: "", phone: "", message: "", productName: "" }); } catch { setMessage({ type: "error", text: t.contact.error }); } finally { @@ -168,7 +185,7 @@ ${formData.message || "—"} value={formData.name} onChange={handleChange} placeholder={t.contact.namePlaceholder} - className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" + className="w-full text-black px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" /> @@ -184,7 +201,7 @@ ${formData.message || "—"} onChange={handleChange} placeholder={t.contact.phonePlaceholder} required - className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" + className="w-full text-black px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" /> @@ -199,7 +216,7 @@ ${formData.message || "—"} onChange={handleChange} placeholder={t.contact.messagePlaceholder} rows={4} - className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none" + className="w-full text-black px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none" /> @@ -214,7 +231,7 @@ ${formData.message || "—"} value={productName ? productName : formData.productName} onChange={handleChange} placeholder={t.contact.product} - className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" + className="w-full text-black px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" /> diff --git a/components/productSection/ProductCard.tsx b/components/productSection/ProductCard.tsx index baf1ae2..c662ff0 100644 --- a/components/productSection/ProductCard.tsx +++ b/components/productSection/ProductCard.tsx @@ -29,7 +29,7 @@ export function ProductCard({ product, onViewDetails }: ProductCardProps) { className="w-full h-full" > {languageIndex?product.name_uz:product.name_ru} diff --git a/components/productSection/ProductModal.tsx b/components/productSection/ProductModal.tsx index 32038c8..b098932 100644 --- a/components/productSection/ProductModal.tsx +++ b/components/productSection/ProductModal.tsx @@ -61,7 +61,7 @@ export function ProductModal({ product, onClose }: ProductModalProps) { {/* Image */}
image { async function getData() { - await axios.get("https://admin.promtechno.uz/api/products/").then((res) => { - console.log("all data main page: ", res?.data); - const allData = res?.data || []; - setAllProducts(allData.slice(0,3)); - }); + await axios + .get("https://admin.promtechno.uz/api/products/") + .then((res) => { + console.log("all data main page: ", res?.data); + const allData = res?.data || []; + setAllProducts(allData.slice(0, 3)); + }); } getData(); }, []); @@ -64,21 +67,25 @@ export function ProductsGrid() { {/* Product Grid */} - - {allProducts.map((product: any) => ( - - - - ))} - + {allProducts && allProducts.length > 0 ? ( + + {allProducts.map((product: any) => ( + + + + ))} + + ) : ( + + )}
-
+
{/* Illustration / Icon */} @@ -54,14 +54,16 @@ export default function EmptyState() { {t.empty_data.description}

-
- - {t.empty_data.back || "Bosh sahifa"} - -
+ {page !== "main" && ( +
+ + {t.empty_data.back || "Bosh sahifa"} + +
+ )}
diff --git a/components/productsPage/products.tsx b/components/productsPage/products.tsx index b897fb6..89ab8bc 100644 --- a/components/productsPage/products.tsx +++ b/components/productsPage/products.tsx @@ -46,7 +46,7 @@ export default function Products() { ))}
) : ( - + )} {/* Product Modal */} {selectedProduct && (