J'suis pas en train de devenir fou nonon

This commit is contained in:
Victor Turgeon 2022-11-06 17:28:57 -05:00
parent c7070de05e
commit 5a2f0fa8b0
2 changed files with 8 additions and 2 deletions

View File

@ -1,8 +1,8 @@
import { Form } from "react-bootstrap"; import { Form } from "react-bootstrap";
const QtySelect = ({ qty }) => { const QtySelect = ({onChange, qty }) => {
return ( return (
<Form.Select className="qty-select"> <Form.Select onChange={(e)=>onChange(e.target.value)} className="qty-select">
{Array.from(Array(qty), (e, i) => { {Array.from(Array(qty), (e, i) => {
return ( return (
<option value={i+1} key={i+1}>{i+1}</option> <option value={i+1} key={i+1}>{i+1}</option>

View File

@ -10,11 +10,16 @@ const MorceauDetail = () => {
const [item, setItem] = useState({}); const [item, setItem] = useState({});
const [imageSrc, setImageSrc] = useState(null); const [imageSrc, setImageSrc] = useState(null);
const [itemQty, setItemQty] = useState(0); const [itemQty, setItemQty] = useState(0);
const [currentQty, setCurrentQty] = useState(1);
const isNoStock = () => { const isNoStock = () => {
return item.status == 1 || item.status == 2 || item.status == 5; return item.status == 1 || item.status == 2 || item.status == 5;
} }
const currentQtyChange = (newQty) =>{
setCurrentQty(newQty);
}
useEffect(() => { useEffect(() => {
document.title = 'Morceaux'; document.title = 'Morceaux';
async function fetchData() { async function fetchData() {
@ -136,6 +141,7 @@ const MorceauDetail = () => {
<div className="detail-container-controls"> <div className="detail-container-controls">
<QtySelect <QtySelect
qty={isNoStock() ? 0 : itemQty} qty={isNoStock() ? 0 : itemQty}
onChange={currentQtyChange}
/> />
<Button disabled={isNoStock()} className="add-to-cart"> <Button disabled={isNoStock()} className="add-to-cart">
Ajouter au panier Ajouter au panier