Files
portal-mini-store-template/src/components/add-to-cart-button.tsx
Ami b1a44f915d feat: portal-mini-store-template with PDPA consent logging
- Payload CMS 3.49.1 + MongoDB
- ConsentLogs collection for PDPA compliance
- CookieBanner component with Accept/Reject/Preferences
- /api/consent endpoint for logging
- Cart, checkout, orders functionality
- Docker compose with MongoDB
2026-04-11 01:01:25 +07:00

67 lines
1.3 KiB
TypeScript

'use client'
import React, { useState } from 'react'
import { Plus, Check } from 'lucide-react'
import { useCart } from '@/lib/cart-context'
import { Button } from '@/components/ui/button'
import type { CartItem } from '@/lib/cart-context'
interface AddToCartButtonProps {
snack: {
id: string
name: string
price: number
category: string
image?: {
url: string
alt?: string
}
}
}
export const AddToCartButton: React.FC<AddToCartButtonProps> = ({ snack }) => {
const { addItem, openCart } = useCart()
const [isAdded, setIsAdded] = useState(false)
const handleAddToCart = () => {
addItem({
id: snack.id,
name: snack.name,
price: snack.price,
category: snack.category,
image: snack.image,
})
setIsAdded(true)
// Show feedback for 1 second
setTimeout(() => {
setIsAdded(false)
}, 1000)
// Optional: Open cart after adding item
// openCart()
}
return (
<Button
onClick={handleAddToCart}
disabled={isAdded}
className={isAdded ? 'bg-green-600 hover:bg-green-600' : ''}
>
{isAdded ? (
<>
<Check className="h-4 w-4 mr-2" />
Added!
</>
) : (
<>
<Plus className="h-4 w-4 mr-2" />
Add to Cart
</>
)}
</Button>
)
}