fix: change handler unit type items

This commit is contained in:
2026-06-24 10:15:19 +03:00
parent 18310195fa
commit f219d1a31b
+7 -3
View File
@@ -2,15 +2,19 @@ import { useState } from "react";
import Arrow from "../components/Arrow"; import Arrow from "../components/Arrow";
export default function CardItem({ item, onAddToCart }) { 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 = () => { const handleIncrement = () => {
setWeight((prev) => parseFloat((prev + 0.1).toFixed(3))); setWeight((prev) => parseFloat((prev + step).toFixed(3)));
}; };
const handleDecrement = () => { const handleDecrement = () => {
setWeight((prev) => setWeight((prev) =>
prev > 0.1 ? parseFloat((prev - 0.1).toFixed(3)) : 0.1, prev > minValue ? parseFloat((prev - step).toFixed(3)) : 0.1,
); );
}; };