From 36fe8937a7642e4f5ad3a0bccb3135a39442e77a Mon Sep 17 00:00:00 2001 From: okbel Date: Tue, 1 Jun 2021 09:34:54 -0300 Subject: [PATCH] sidebar cart --- components/cart/CartItem/CartItem.module.css | 5 ++++ components/cart/CartItem/CartItem.tsx | 24 +++++++++---------- .../CheckoutSidebarView.tsx | 12 ++++++---- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/components/cart/CartItem/CartItem.module.css b/components/cart/CartItem/CartItem.module.css index a4d62aeca..feffa0f3a 100644 --- a/components/cart/CartItem/CartItem.module.css +++ b/components/cart/CartItem/CartItem.module.css @@ -41,3 +41,8 @@ left: 30% !important; top: 30% !important; } + +.productName { + @apply font-medium cursor-pointer pb-1; + margin-top: -4px; +} diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx index 990c94a17..c03c2a179 100644 --- a/components/cart/CartItem/CartItem.tsx +++ b/components/cart/CartItem/CartItem.tsx @@ -19,11 +19,11 @@ type ItemOption = { const CartItem = ({ item, + variant = 'default', currencyCode, - noEdit = false, ...rest }: { - noEdit?: boolean + variant: 'default' | 'display' item: LineItem currencyCode: string }) => { @@ -46,7 +46,6 @@ const CartItem = ({ const handleQuantity = (e: ChangeEvent) => { const val = Number(e.target.value) - if (Number.isInteger(val) && val >= 0) { setQuantity(Number(e.target.value)) } @@ -54,7 +53,6 @@ const CartItem = ({ const handleBlur = () => { const val = Number(quantity) - if (val !== item.quantity) { updateQuantity(val) } @@ -62,7 +60,6 @@ const CartItem = ({ const increaseQuantity = (n = 1) => { const val = Number(quantity) + n - if (Number.isInteger(val) && val >= 0) { setQuantity(val) updateQuantity(val) @@ -71,7 +68,6 @@ const CartItem = ({ const handleRemove = async () => { setRemoving(true) - try { // If this action succeeds then there's no need to do `setRemoving(true)` // because the component will be removed from the view @@ -80,6 +76,7 @@ const CartItem = ({ setRemoving(false) } } + // TODO: Add a type for this const options = (item as any).options @@ -114,14 +111,14 @@ const CartItem = ({
closeSidebarIfPresent()} > {item.name} - {options && options.length > 0 ? ( -
+ {options && options.length > 0 && ( +
{options.map((option: ItemOption, i: number) => (
))}
- ) : null} + )} + {variant === 'display' && ( +
{quantity}x
+ )}
{price}
- {!noEdit ? ( + {variant === 'default' && (
- ) : ( -
x{quantity}
)} ) diff --git a/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx b/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx index 9d7363290..c9dab3d83 100644 --- a/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx +++ b/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx @@ -144,13 +144,13 @@ const CheckoutSidebarView: FC = () => {
- -
+
Total {total}
- */} +