openinventory ofpd update viq admin

This commit is contained in:
Sibunnayak 2024-10-28 14:12:45 +05:30
parent faeb4faa5b
commit 1ec4d8951f

View File

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