remove animate presence

This commit is contained in:
Rami Bitar
2026-05-08 00:29:11 -04:00
parent 884538488f
commit b92d35a148
2 changed files with 162 additions and 293 deletions

View File

@@ -4,17 +4,39 @@ import React from 'react';
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 {
Empty,
EmptyHeader,
EmptyTitle,
EmptyDescription,
EmptyContent,
} from '@/components/ui/empty';
import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
SheetBody,
SheetFooter,
} from '@/components/ui/sheet';
const CartDrawer: React.FC = () => {
const { isOpen, closeCart, items, itemCount, totalAmount, checkoutUrl, loading, removeItem, updateItemQuantity } = useShopifyCart();
const {
isOpen,
closeCart,
items,
itemCount,
totalAmount,
checkoutUrl,
loading,
removeItem,
updateItemQuantity,
} = useShopifyCart();
const handleCheckout = () => {
if (checkoutUrl) {
@@ -22,42 +44,57 @@ const CartDrawer: React.FC = () => {
}
};
const getItemImage = (item: typeof items[0]) => {
const getItemImage = (item: (typeof items)[0]) => {
return item.merchandise.image?.url;
};
const getSelectedOptions = (item: typeof items[0]) => {
const getSelectedOptions = (item: (typeof items)[0]) => {
return item.merchandise.selectedOptions ?? [];
};
return (
<Sheet open={isOpen} onOpenChange={(open) => !open && closeCart()} side="right">
<SheetContent className="w-full sm:max-w-md">
<Sheet open={isOpen} onOpenChange={(open) => !open && closeCart()}>
<SheetContent
side="right"
className="w-full max-w-md"
showCloseButton={false}
>
{/* Header */}
<SheetHeader>
<SheetTitle className="text-base">
Shopping Cart ({itemCount})
</SheetTitle>
<SheetHeader className="h-14 min-h-0 px-4 py-3 flex items-center border-b border-border">
<div className="flex items-center justify-between w-full">
<SheetTitle className="text-base">
Shopping Cart ({itemCount})
</SheetTitle>
<Button onClick={closeCart} variant="ghost" size="icon-sm">
<RiCloseLine size={20} />
</Button>
</div>
</SheetHeader>
{/* Cart Items */}
<SheetBody>
<div className="flex-1 overflow-y-auto px-6 py-4">
{loading && items.length === 0 ? (
<div className="flex items-center justify-center py-12">
<Spinner size="lg" />
</div>
) : items.length === 0 ? (
<div className="text-center py-12">
<i className="ri-shopping-cart-line text-6xl text-gray-300 mb-4 block"></i>
<h3 className="text-lg font-semibold text-gray-600 mb-2">Your cart is empty</h3>
<p className="text-gray-500 mb-6">Add some products to get started!</p>
<Button
onClick={closeCart}
className="font-heading"
>
Continue Shopping
</Button>
</div>
<Empty className="border-0">
<EmptyContent>
<EmptyHeader>
<EmptyTitle>Your cart is empty</EmptyTitle>
<EmptyDescription>
Add some products to get started!
</EmptyDescription>
</EmptyHeader>
<Button
onClick={closeCart}
variant="outline"
className="rounded-full"
>
Continue Shopping
</Button>
</EmptyContent>
</Empty>
) : (
<div className="space-y-6">
{items.map((item) => {
@@ -65,7 +102,10 @@ const CartDrawer: React.FC = () => {
const selectedOptions = getSelectedOptions(item);
return (
<div key={item.id} className="flex items-start space-x-4 pb-6 border-b border-gray-200 last:border-b-0">
<div
key={item.id}
className="flex items-start space-x-4 pb-6 border-b border-gray-200 last:border-b-0"
>
{/* Product Image */}
<div className="w-20 h-20 bg-gray-100 rounded-lg overflow-hidden flex-shrink-0">
{image ? (
@@ -76,7 +116,7 @@ const CartDrawer: React.FC = () => {
/>
) : (
<div className="w-full h-full flex items-center justify-center text-gray-400">
<i className="ri-image-line text-2xl"></i>
<RiImageLine size={24} />
</div>
)}
</div>
@@ -93,7 +133,9 @@ const CartDrawer: React.FC = () => {
{selectedOptions.map((option, index) => (
<span key={option.name}>
{option.value}
{index < selectedOptions.length - 1 ? ' / ' : ''}
{index < selectedOptions.length - 1
? ' / '
: ''}
</span>
))}
</div>
@@ -103,25 +145,29 @@ const CartDrawer: React.FC = () => {
<div className="flex items-center mt-3">
<div className="flex items-center border border-gray-300 rounded-lg">
<Button
onClick={() => updateItemQuantity(item.id, item.quantity - 1)}
onClick={() =>
updateItemQuantity(item.id, item.quantity - 1)
}
variant="ghost"
size="icon-sm"
disabled={item.quantity <= 1 || loading}
className="h-7 w-7"
>
<i className="ri-subtract-line text-sm"></i>
<RiSubtractLine size={14} />
</Button>
<span className="px-2 py-1 font-semibold min-w-[30px] text-center text-sm">
{item.quantity}
</span>
<Button
onClick={() => updateItemQuantity(item.id, item.quantity + 1)}
onClick={() =>
updateItemQuantity(item.id, item.quantity + 1)
}
variant="ghost"
size="icon-sm"
disabled={loading}
className="h-7 w-7"
>
<i className="ri-add-line text-sm"></i>
<RiAddLine size={14} />
</Button>
</div>
</div>
@@ -141,9 +187,9 @@ const CartDrawer: React.FC = () => {
variant="ghost"
size="icon-sm"
disabled={loading}
className="text-gray-400 hover:text-red-500"
className="text-gray-400 hover:text-gray-700"
>
<i className="ri-delete-bin-line text-lg"></i>
<RiCloseLine size={18} />
</Button>
</div>
</div>
@@ -151,11 +197,11 @@ const CartDrawer: React.FC = () => {
})}
</div>
)}
</SheetBody>
</div>
{/* Footer - Checkout Section */}
{items.length > 0 && (
<SheetFooter className="flex-col sm:flex-col sm:justify-start gap-0">
<div className="border-t border-border p-6">
{/* Subtotal */}
<div className="flex items-center justify-between mb-4">
<span className="text-base font-semibold">Subtotal</span>
@@ -178,7 +224,7 @@ const CartDrawer: React.FC = () => {
>
{loading ? (
<span className="flex items-center justify-center space-x-2">
<Spinner size="sm" />
<Loader size={16} />
<span>Processing...</span>
</span>
) : (
@@ -186,15 +232,11 @@ const CartDrawer: React.FC = () => {
)}
</Button>
<Button
onClick={closeCart}
variant="link"
className="w-full"
>
<Button onClick={closeCart} variant="link" className="w-full">
Continue Shopping
</Button>
</div>
</SheetFooter>
</div>
)}
</SheetContent>
</Sheet>