Skip to content

Commit

Permalink
Made size selection required if size options exist
Browse files Browse the repository at this point in the history
  • Loading branch information
calvadev committed Sep 11, 2024
1 parent 239dbde commit ece4dbd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion components/utility-components/checkout-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function CheckoutCard({
const [selectedSize, setSelectedSize] = useState<string | undefined>(
undefined,
);
const [hasSizes, setHasSizes] = useState(false);

const toggleExpand = () => {
setIsExpanded(!isExpanded);
Expand Down Expand Up @@ -83,6 +84,16 @@ export default function CheckoutCard({
}
}, [selectedImage]);

useEffect(() => {
setHasSizes(
!!(
sizes &&
sizes.length > 0 &&
sizes.some((size) => (sizeQuantities?.get(size) || 0) > 0)
),
);
}, [sizes, sizeQuantities]);

const toggleBuyNow = () => {
setIsBeingPaid(!isBeingPaid);
};
Expand Down Expand Up @@ -230,8 +241,13 @@ export default function CheckoutCard({
</div>
<div className="flex w-full gap-2">
<Button
className={SHOPSTRBUTTONCLASSNAMES}
className={`${SHOPSTRBUTTONCLASSNAMES} ${
hasSizes && !selectedSize
? "cursor-not-allowed opacity-50"
: ""
}`}
onClick={toggleBuyNow}
disabled={hasSizes && !selectedSize}
>
Buy Now
</Button>
Expand Down

0 comments on commit ece4dbd

Please sign in to comment.