DISCOUNTCODEINPUT COMPONENT
Input field for discount codes with validation states and feedback messages.
PROPS
| Prop | Type | Description |
|---|---|---|
| onApply | (code: string) => Promise<void> | Apply discount callback |
| variant | 'default' | 'inline' | Display variant |
| disabled | boolean | Disable input |
Variants
Default (Card Style)
Try entering "WELCOME10" to see success state
1<DiscountCodeInput2 variant="default"3 onApply={handleApplyDiscount}4/>Inline Style
1<DiscountCodeInput2 variant="inline"3 onApply={handleApplyDiscount}4/>Success State
Error State
USAGE EXAMPLES
IMPLEMENTATION WITH CART
1import { DiscountCodeInput } from '@/components/fanbace/discount-code-input';2import { useCart } from '@/lib/sdk';3import { toast } from 'sonner';4 5export default function CheckoutPage() {6 const { applyDiscount } = useCart();7 8 const handleApplyDiscount = async (code: string) => {9 try {10 await applyDiscount(code);11 toast.success('Discount applied!');12 } catch (error) {13 toast.error('Invalid discount code');14 }15 };16 17 return (18 <div>19 <DiscountCodeInput onApply={handleApplyDiscount} />20 </div>21 );22}