From f219d1a31b69f09bab0a875e2497b243ac245066 Mon Sep 17 00:00:00 2001 From: LeonG11 Date: Wed, 24 Jun 2026 10:15:19 +0300 Subject: [PATCH] fix: change handler unit type items --- frontend/src/components/CardItem.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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, ); };