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

This commit is contained in:
ROSHAN GARG 2024-10-28 10:33:47 +05:30
parent 2891b634a2
commit 983186c56d

View File

@ -21,7 +21,7 @@ import Swal from 'sweetalert2'
function StockTable() { function StockTable() {
const [stocks, setStocks] = useState([]) // Store stock data const [stocks, setStocks] = useState([]) // Store stock data
const [loading, setLoading] = useState(true) // Loading state const [loading, setLoading] = useState(true) // Loading state
const [rowsPerPage, setRowsPerPage] = useState(5) const [rowsPerPage, setRowsPerPage] = useState(10)
const [page, setPage] = useState(0) const [page, setPage] = useState(0)
const token = isAutheticated() const token = isAutheticated()
@ -46,7 +46,9 @@ function StockTable() {
const handleStockChange = (productId, value) => { const handleStockChange = (productId, value) => {
setStocks((prevStocks) => setStocks((prevStocks) =>
prevStocks.map((stock) => 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 // Submit updated stock values
const handleSubmit = async () => { const handleSubmit = async () => {
try { try {
await Axios.put( const res = await Axios.put(
'/api/pd/stock-update', '/api/pd/stock-update',
{ products: stocks }, { products: stocks },
{ {
@ -65,6 +67,8 @@ function StockTable() {
}, },
}, },
) )
console.log(res)
// setStocks(res.data.stock)
Swal.fire('success!', 'Stock updated successfully', 'success') Swal.fire('success!', 'Stock updated successfully', 'success')
} catch (error) { } catch (error) {
console.error('Error updating stock:', error) console.error('Error updating stock:', error)
@ -95,7 +99,7 @@ function StockTable() {
<TableRow> <TableRow>
<TableCell>Product Name</TableCell> <TableCell>Product Name</TableCell>
<TableCell>SKU</TableCell> <TableCell>SKU</TableCell>
<TableCell>Current Stock</TableCell> <TableCell>Opening Inventory</TableCell>
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
@ -113,7 +117,7 @@ function StockTable() {
<TableCell> <TableCell>
<TextField <TextField
type="number" type="number"
value={stock.Stock} value={stock.openingInventory}
onChange={(e) => handleStockChange(stock.productid, e.target.value)} onChange={(e) => handleStockChange(stock.productid, e.target.value)}
variant="outlined" variant="outlined"
size="small" size="small"