From b3952a270260ff5d9d825e9e5e0cec554bb67df2 Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Sat, 20 Sep 2025 08:28:35 -0700 Subject: [PATCH] Fix: Create product prevent API call if product name field is empty and not valid --- .../products/components/CreateProductDialog.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vite/src/views/products/products/components/CreateProductDialog.tsx b/vite/src/views/products/products/components/CreateProductDialog.tsx index d52971ed7..ca64819db 100644 --- a/vite/src/views/products/products/components/CreateProductDialog.tsx +++ b/vite/src/views/products/products/components/CreateProductDialog.tsx @@ -43,6 +43,17 @@ function CreateProduct({ const navigate = useNavigate(); const handleCreateClicked = async () => { + const productName = product.name?.trim() || ""; + + if (!/^[a-zA-Z0-9 _-]+$/.test(productName)) { + toast.error( + !productName + ? "Product name is required" + : "Product name can only contain alphanumeric characters, dashes (-), and underscores (_)" + ); + return; + } + setLoading(true); try { const newProduct = await ProductService.createProduct(