stock
Some checks failed
NPM Installation / build (16.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (16.x, windows-latest) (push) Has been cancelled
NPM Installation / build (17.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (17.x, windows-latest) (push) Has been cancelled
NPM Installation / build (18.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (18.x, windows-latest) (push) Has been cancelled
Some checks failed
NPM Installation / build (16.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (16.x, windows-latest) (push) Has been cancelled
NPM Installation / build (17.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (17.x, windows-latest) (push) Has been cancelled
NPM Installation / build (18.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (18.x, windows-latest) (push) Has been cancelled
This commit is contained in:
parent
2891b634a2
commit
983186c56d
@ -21,7 +21,7 @@ import Swal from 'sweetalert2'
|
||||
function StockTable() {
|
||||
const [stocks, setStocks] = useState([]) // Store stock data
|
||||
const [loading, setLoading] = useState(true) // Loading state
|
||||
const [rowsPerPage, setRowsPerPage] = useState(5)
|
||||
const [rowsPerPage, setRowsPerPage] = useState(10)
|
||||
const [page, setPage] = useState(0)
|
||||
const token = isAutheticated()
|
||||
|
||||
@ -46,7 +46,9 @@ function StockTable() {
|
||||
const handleStockChange = (productId, value) => {
|
||||
setStocks((prevStocks) =>
|
||||
prevStocks.map((stock) =>
|
||||
stock.productid === productId ? { ...stock, Stock: parseInt(value, 10) || 0 } : stock,
|
||||
stock.productid === productId
|
||||
? { ...stock, openingInventory: parseInt(value, 10) || 0 }
|
||||
: stock,
|
||||
),
|
||||
)
|
||||
}
|
||||
@ -55,7 +57,7 @@ function StockTable() {
|
||||
// Submit updated stock values
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
await Axios.put(
|
||||
const res = await Axios.put(
|
||||
'/api/pd/stock-update',
|
||||
{ products: stocks },
|
||||
{
|
||||
@ -65,6 +67,8 @@ function StockTable() {
|
||||
},
|
||||
},
|
||||
)
|
||||
console.log(res)
|
||||
// setStocks(res.data.stock)
|
||||
Swal.fire('success!', 'Stock updated successfully', 'success')
|
||||
} catch (error) {
|
||||
console.error('Error updating stock:', error)
|
||||
@ -95,7 +99,7 @@ function StockTable() {
|
||||
<TableRow>
|
||||
<TableCell>Product Name</TableCell>
|
||||
<TableCell>SKU</TableCell>
|
||||
<TableCell>Current Stock</TableCell>
|
||||
<TableCell>Opening Inventory</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
@ -113,7 +117,7 @@ function StockTable() {
|
||||
<TableCell>
|
||||
<TextField
|
||||
type="number"
|
||||
value={stock.Stock}
|
||||
value={stock.openingInventory}
|
||||
onChange={(e) => handleStockChange(stock.productid, e.target.value)}
|
||||
variant="outlined"
|
||||
size="small"
|
||||
|
Loading…
Reference in New Issue
Block a user