From ef941245d1d1916d8d0aadab55fde5d27f16a8d4 Mon Sep 17 00:00:00 2001 From: Rami Bitar Date: Fri, 8 May 2026 09:21:49 -0400 Subject: [PATCH] Update shopify cart --- components/commerce/cart-drawer.tsx | 17 ++--- components/commerce/product-details.tsx | 10 ++- components/navigation/navigation.tsx | 85 ------------------------- contexts/shopify-context.tsx | 5 ++ index.html | 2 +- 5 files changed, 21 insertions(+), 98 deletions(-) diff --git a/components/commerce/cart-drawer.tsx b/components/commerce/cart-drawer.tsx index ae79f05..3c92a02 100644 --- a/components/commerce/cart-drawer.tsx +++ b/components/commerce/cart-drawer.tsx @@ -5,12 +5,7 @@ import { useShopifyCart, redirectToCheckout } from '@/hooks/use-shopify-cart'; import { Button } from '@/components/ui/button'; import { Spinner } from '@/components/ui/spinner'; import { Loader } from '@/components/ui/loader'; -import { - RiCloseLine, - RiImageLine, - RiSubtractLine, - RiAddLine, -} from '@remixicon/react'; +import { X, ImageIcon, Minus, Plus } from 'lucide-react'; import { Empty, EmptyHeader, @@ -66,7 +61,7 @@ const CartDrawer: React.FC = () => { Shopping Cart ({itemCount}) @@ -116,7 +111,7 @@ const CartDrawer: React.FC = () => { /> ) : (
- +
)} @@ -153,7 +148,7 @@ const CartDrawer: React.FC = () => { disabled={item.quantity <= 1 || loading} className="h-7 w-7" > - + {item.quantity} @@ -167,7 +162,7 @@ const CartDrawer: React.FC = () => { disabled={loading} className="h-7 w-7" > - + @@ -189,7 +184,7 @@ const CartDrawer: React.FC = () => { disabled={loading} className="text-gray-400 hover:text-gray-700" > - + diff --git a/components/commerce/product-details.tsx b/components/commerce/product-details.tsx index 315c83c..d68eda4 100644 --- a/components/commerce/product-details.tsx +++ b/components/commerce/product-details.tsx @@ -6,6 +6,7 @@ import { useShopifyCart } from "@/hooks/use-shopify-cart"; import { Typography } from "@/components/Typography"; import { cn } from "@/lib/utils"; import { Skeleton } from "@/components/ui/skeleton"; +import { Loader } from "@/components/ui/loader"; export type ProductDetailsProps = { product: ShopifyProduct | null; @@ -191,7 +192,14 @@ export function ProductDetailsView({ product: selected }: ProductDetailsProps) { disabled={!variant || adding} className="flex-1 rounded-full bg-foreground px-6 py-3 text-sm font-medium tracking-wide text-background transition-opacity hover:opacity-90 disabled:opacity-50" > - {adding ? "Adding…" : "Add to bag"} + {adding ? ( + + + Adding… + + ) : ( + "Add to bag" + )} diff --git a/components/navigation/navigation.tsx b/components/navigation/navigation.tsx index 22d857f..ef5432a 100644 --- a/components/navigation/navigation.tsx +++ b/components/navigation/navigation.tsx @@ -29,7 +29,6 @@ export function Navigation({ bannerTone, }: NavigationProps) { const [mobileOpen, setMobileOpen] = useState(false); - const [cartOpen, setCartOpen] = useState(false); const cart = useShopifyCart(); const itemCount = cart?.itemCount ?? 0; @@ -153,90 +152,6 @@ export function Navigation({ - {/* Cart drawer */} - - - - Cart - - -
- {cart?.items?.length ? ( -
    - {cart.items.map((line: any) => ( -
  • -
    - {line.merchandise?.product?.images?.edges?.[0]?.node?.url ? ( - {line.merchandise.product.title} - ) : null} -
    -
    -

    {line.merchandise?.product?.title}

    - {line.merchandise?.title && line.merchandise.title !== "Default Title" ? ( -

    {line.merchandise.title}

    - ) : null} -
    -
    - - {line.quantity} - -
    - - {line.merchandise?.price - ? new Intl.NumberFormat("en-US", { - style: "currency", - currency: line.merchandise.price.currencyCode, - }).format(parseFloat(line.merchandise.price.amount) * line.quantity) - : null} - -
    -
    -
  • - ))} -
- ) : ( -
- -

Your cart is empty.

-
- )} -
- - {cart?.items?.length ? ( -
-
- Subtotal - - {new Intl.NumberFormat("en-US", { - style: "currency", - currency: cart.cart?.cost?.totalAmount?.currencyCode ?? "USD", - }).format(cart.totalAmount)} - -
- - Checkout - -
- ) : null} -
-
); } diff --git a/contexts/shopify-context.tsx b/contexts/shopify-context.tsx index 4124d4f..cdaeac7 100644 --- a/contexts/shopify-context.tsx +++ b/contexts/shopify-context.tsx @@ -1,6 +1,7 @@ 'use client'; import React, { createContext, useContext, useState, useCallback, useEffect, useMemo } from 'react'; +import { ShoppingBag } from 'lucide-react'; import { createCart, getCart, @@ -9,6 +10,8 @@ import { updateCartLines, } from '@/hooks/use-shopify-cart'; import { setShopifyCredentials } from '@/services/shopify/client'; +import CartDrawer from '@/components/commerce/cart-drawer'; +import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet'; const CART_ID_KEY = 'cartId'; @@ -200,6 +203,7 @@ export const ShopifyProvider: React.FC<{ ]); setCart(updatedCart); + setIsOpen(true); return updatedCart; } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Failed to add item to cart'; @@ -284,6 +288,7 @@ export const ShopifyProvider: React.FC<{ refreshCart, }}> {children} + ); diff --git a/index.html b/index.html index 05cef93..bdb1b9c 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - React Editor — Shopify Demo + Shopify Storefront