vat_wms/resources/js/Components/modals/SetStockModal.tsx
2025-06-02 07:36:24 +02:00

50 lines
1.4 KiB
TypeScript

// components/modals/SetStockModal.tsx
import React from 'react'
import axios from 'axios'
import { toast } from 'react-hot-toast'
interface Props {
onClose: () => void
}
const SetStockModal: React.FC<Props> = ({ onClose }) => {
const [quantity, setQuantity] = React.useState(0)
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
try {
await axios.post('/api/set-stock', { quantity }, { withCredentials: true })
toast.success('Stock set!')
onClose()
} catch {
toast.error('Failed to set stock')
}
}
return (
<form onSubmit={handleSubmit}>
<h3 className="font-bold text-lg">Set Stock</h3>
<label className="label">
<span className="label-text">Quantity</span>
</label>
<input
type="number"
value={quantity}
onChange={e => setQuantity(+e.target.value)}
className="input input-bordered w-full"
required
/>
<div className="modal-action">
<button type="button" className="btn" onClick={onClose}>
Cancel
</button>
<button type="submit" className="btn btn-primary">
Submit
</button>
</div>
</form>
)
}
export default SetStockModal