diff --git a/src/views/PrincipalDistributors/OpeningInventory.js b/src/views/PrincipalDistributors/OpeningInventory.js index f3a9813..084cfbd 100644 --- a/src/views/PrincipalDistributors/OpeningInventory.js +++ b/src/views/PrincipalDistributors/OpeningInventory.js @@ -14,6 +14,7 @@ const DistributorOpeningInventory = () => { const { id, distributortype } = useParams(); const [loading, setLoading] = useState(false); + const [success, setSuccess] = useState(false); const [productsData, setProductsData] = useState([]); const [allProductsData, setAllProductsData] = useState([]); const [categories, setCategories] = useState([]); @@ -112,7 +113,7 @@ const DistributorOpeningInventory = () => { }, [getUserDetails]); useEffect(() => { getProductsData(); - }, [currentPage, itemPerPage]); + }, [success, currentPage, itemPerPage]); const getCatagories = () => { axios .get(`/api/category/getCategories`, { @@ -199,6 +200,8 @@ const DistributorOpeningInventory = () => { { headers: { Authorization: `Bearer ${token}` } } ); swal("Success", "Stocks updated successfully!", "success"); + setUpdatedStocks({}); + setSuccess((prev) => !prev); } catch (error) { swal("Error", "Failed to update stocks!", "error"); } @@ -359,7 +362,7 @@ const DistributorOpeningInventory = () => { className="mt-4" variant="contained" color="primary" - // onClick={handleSubmitStocks} + onClick={handleSubmitStocks} disabled={loading} > Save @@ -435,18 +438,18 @@ const DistributorOpeningInventory = () => { { - // Check if the input is a valid number or empty const value = e.target.value; - if ( - value === "" || - /^[0-9]*$/.test(value) - ) { - // Allow only numbers or empty - handleStockChange(product.SKU, value); + if (/^[0-9]*$/.test(value)) { + // Allow only numbers or empty input, but set 0 if input is empty + handleStockChange( + product.SKU, + value === "" ? 0 : value + ); } }} className="form-control"