diff --git a/frontend/src/components/CardItem.jsx b/frontend/src/components/CardItem.jsx index 9834626..2e9782d 100644 --- a/frontend/src/components/CardItem.jsx +++ b/frontend/src/components/CardItem.jsx @@ -2,15 +2,19 @@ import { useState } from "react"; import Arrow from "../components/Arrow"; export default function CardItem({ item, onAddToCart }) { - const [weight, setWeight] = useState(0.1); + const isPiece = item.unit_type === "piece"; + const step = isPiece ? 1 : 0.1; + const minValue = isPiece ? 1 : 0.1; + + const [weight, setWeight] = useState(minValue); const handleIncrement = () => { - setWeight((prev) => parseFloat((prev + 0.1).toFixed(3))); + setWeight((prev) => parseFloat((prev + step).toFixed(3))); }; const handleDecrement = () => { setWeight((prev) => - prev > 0.1 ? parseFloat((prev - 0.1).toFixed(3)) : 0.1, + prev > minValue ? parseFloat((prev - step).toFixed(3)) : 0.1, ); };