fix: change handler unit type items
This commit is contained in:
@@ -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,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user