Browse Source

handle max stock

master
azri 12 hours ago
parent
commit
3382f36790
1 changed files with 4 additions and 4 deletions
  1. 4
    4
      src/components/ProductDetails/ProductDetails.jsx

+ 4
- 4
src/components/ProductDetails/ProductDetails.jsx View File

166
   }
166
   }
167
 
167
 
168
   const handleIncrement = () => {
168
   const handleIncrement = () => {
169
-    setQuantity((prevQuantity) => prevQuantity + 1);
169
+    setQuantity((prevQuantity) => (prevQuantity >= variantSelection.quantityAvailable ? variantSelection.quantityAvailable : prevQuantity + 1));
170
   };
170
   };
171
 
171
 
172
   const handleDecrement = () => {
172
   const handleDecrement = () => {
195
           <Typography
195
           <Typography
196
             variant="body1"
196
             variant="body1"
197
           >
197
           >
198
-            IN STOCK: {`${variantSelection?.quantityAvailable}`}
198
+            {(variantSelection?.quantityAvailable == 0) ? <span style={{color:"red", fontWeight:"bolder"}}>{`OUT OF STOCK`}</span> : `IN STOCK: ${variantSelection?.quantityAvailable}`}
199
           </Typography>
199
           </Typography>
200
         </Box>
200
         </Box>
201
 
201
 
241
               variant="contained"
241
               variant="contained"
242
               color="primary"
242
               color="primary"
243
               sx={{ width: "35px" }}
243
               sx={{ width: "35px" }}
244
-              disabled={variantSelection?.quantityAvailable == 0}
244
+              disabled={variantSelection?.quantityAvailable == 0 || quantity == 1}
245
               onClick={handleDecrement}
245
               onClick={handleDecrement}
246
             >
246
             >
247
               <RemoveIcon />
247
               <RemoveIcon />
259
               variant="contained"
259
               variant="contained"
260
               color="primary"
260
               color="primary"
261
               sx={{ width: "35px" }}
261
               sx={{ width: "35px" }}
262
-              disabled={variantSelection?.quantityAvailable == 0}
262
+              disabled={variantSelection?.quantityAvailable == 0 || quantity == variantSelection?.quantityAvailable}
263
               onClick={handleIncrement}
263
               onClick={handleIncrement}
264
             >
264
             >
265
               <AddIcon />
265
               <AddIcon />

Loading…
Cancel
Save