costco-grocery-list/frontend/src/components/modals/ConfirmBuyModal.jsx
2026-01-02 15:59:01 -08:00

68 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useState } from "react";
import "../../styles/ConfirmBuyModal.css";
export default function ConfirmBuyModal({ item, onConfirm, onCancel }) {
const [quantity, setQuantity] = useState(item.quantity);
const maxQuantity = item.quantity;
const handleIncrement = () => {
if (quantity < maxQuantity) {
setQuantity(prev => prev + 1);
}
};
const handleDecrement = () => {
if (quantity > 1) {
setQuantity(prev => prev - 1);
}
};
const handleConfirm = () => {
onConfirm(quantity);
};
return (
<div className="confirm-buy-modal-overlay" onClick={onCancel}>
<div className="confirm-buy-modal" onClick={(e) => e.stopPropagation()}>
<h2>Mark as Bought</h2>
<p className="confirm-buy-item-name">"{item.item_name}"</p>
<div className="confirm-buy-quantity-section">
<p className="confirm-buy-label">Quantity to buy:</p>
<div className="confirm-buy-counter">
<button
onClick={handleDecrement}
className="confirm-buy-counter-btn"
disabled={quantity <= 1}
>
</button>
<input
type="number"
value={quantity}
readOnly
className="confirm-buy-counter-display"
/>
<button
onClick={handleIncrement}
className="confirm-buy-counter-btn"
disabled={quantity >= maxQuantity}
>
+
</button>
</div>
</div>
<div className="confirm-buy-actions">
<button onClick={onCancel} className="confirm-buy-cancel">
Cancel
</button>
<button onClick={handleConfirm} className="confirm-buy-confirm">
Mark as Bought
</button>
</div>
</div>
</div>
);
}